using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using skyscraper5.Skyscraper;

namespace skyscraper8.Skyscraper.Security.AccessControl
{
	internal class ViaccessKey : MultipartKey
	{
		public ViaccessKey(uint viaccessGroup)
		{
			Group = viaccessGroup;
		}

		public uint Group { get; set; }

		public bool SetHint(string viaccessKeyType, byte[] keyData)
		{
			viaccessKeyType = viaccessKeyType.ToUpper();
			switch (viaccessKeyType)
			{
				case "00":
				case "01":
				case "02":
				case "03":
				case "04":
				case "05":
				case "06":
				case "07":
				case "08":
				case "09":
				case "0A":
				case "0B":
				case "0C":
				case "0D":
				case "0E":
				case "0F":
					uint keyNUmber = viaccessKeyType.HexToUint32BE();
					keyNUmber >>= 24;
					if (Keyset == null)
						Keyset = new byte[16][];
					Keyset[keyNUmber] = keyData;
					return true;
				case "D1":
					Des1Key = keyData;
					return true;
				case "X1":
					XorArray = keyData;
					return true;
				case "P1":
					PermArray = keyData;
					return true;
				case "C1":
					ChainArray = keyData;
					return true;
				case "T1":
					TransformTable = keyData;
					return true;
				default:
					return false;
			}
		}

		public byte[] TransformTable { get; set; }

		public byte[] ChainArray { get; set; }

		public byte[] PermArray { get; set; }

		public byte[] XorArray { get; set; }

		public byte[] Des1Key { get; set; }

		public byte[][] Keyset { get; private set; }
	}
}
