示例#1
0
        public void Keys_SameByteArray_AreEqual(ToxKeyType keyType, int keySize)
        {
            var key  = new byte[keySize];
            var key1 = new ToxKey(keyType, key);
            var key2 = new ToxKey(keyType, key);

            Assert.AreEqual(key1, key2);
        }
示例#2
0
        public void GetBytes_InputByteArray_AreNotSame(ToxKeyType keyType, int keySize)
        {
            var input  = new byte[keySize];
            var key    = new ToxKey(keyType, input);
            var result = key.GetBytes();

            Assert.AreNotSame(input, result);
        }
示例#3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ToxKey"/> class
        /// </summary>
        /// <param name="type"></param>
        /// <param name="key"></param>
        public ToxKey(ToxKeyType type, [NotNull] byte[] key)
        {
            if (key.Length != KeySize(type))
            {
                throw new ArgumentException(nameof(key));
            }

            this.KeyType = type;
            this.key     = (byte[])key.Clone();
        }
示例#4
0
        private static int KeySize(ToxKeyType type)
        {
            switch (type)
            {
            case ToxKeyType.Public:
                return(ToxConstants.PublicKeySize);

            case ToxKeyType.Secret:
                return(ToxConstants.SecretKeySize);
            }

            throw new NotImplementedException();
        }
示例#5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ToxKey"/> class
 /// </summary>
 /// <param name="type"></param>
 /// <param name="key"></param>
 public ToxKey(ToxKeyType type, string key)
 {
     KeyType = type;
     _key    = ToxTools.StringToHexBin(key);
 }
示例#6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ToxKey"/> class
 /// </summary>
 /// <param name="type"></param>
 /// <param name="key"></param>
 public ToxKey(ToxKeyType type, byte[] key)
 {
     KeyType = type;
     _key    = key;
 }
示例#7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ToxKey"/> class
 /// </summary>
 /// <param name="type"></param>
 /// <param name="key"></param>
 public ToxKey(ToxKeyType type, string key)
 {
     KeyType = type;
     this.key = ToxTools.StringToHexBin(key);
 }
示例#8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ToxKey"/> class
 /// </summary>
 /// <param name="type"></param>
 /// <param name="key"></param>
 public ToxKey(ToxKeyType type, byte[] key)
 {
     KeyType = type;
     this.key = key;
 }
示例#9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ToxKey"/> class
 /// </summary>
 /// <param name="type"></param>
 /// <param name="key"></param>
 public ToxKey(ToxKeyType type, [NotNull] string key) : this(type, ToxTools.StringToHexBin(key))
 {
 }