GetBytes() public method

Retrieves a byte array of the tox key.
public GetBytes ( ) : byte[]
return byte[]
Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of tox dns3.
        /// </summary>
        /// <param name="publicKey">The public key that this instance of toxdns should be initialized with.</param>
        public ToxDns(ToxKey publicKey)
        {
            _toxDns3 = ToxDnsFunctions.New(publicKey.GetBytes());

            if (_toxDns3 == null || _toxDns3.IsInvalid)
                throw new Exception("Could not create a new tox_dns3 instance with the provided publicKey");
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of Tox. If no secret key is specified, toxcore will generate a new keypair.
        /// </summary>
        /// <param name="options">The options to initialize this instance of Tox with.</param>
        /// <param name="secretKey">Optionally, specify the secret key to initialize this instance of Tox with. Must be ToxConstants.SecretKeySize bytes in size.</param>
        public Tox(ToxOptions options, ToxKey secretKey = null)
        {
            var error = ToxErrorNew.Ok;
            var optionsStruct = options.Struct;

            if (secretKey != null)
                optionsStruct.SetData(secretKey.GetBytes(), ToxSaveDataType.SecretKey);

            _tox = ToxFunctions.New(ref optionsStruct, ref error);

            if (_tox == null || _tox.IsInvalid || error != ToxErrorNew.Ok)
                throw new Exception("Could not create a new instance of tox, error: " + error.ToString());

            optionsStruct.Free();
            Options = options;
        }
Esempio n. 3
0
        /// <summary>
        /// Creates a new tox id with the specified public key and nospam.
        /// </summary>
        /// <param name="publicKey">Public key to create this Tox ID with.</param>
        /// <param name="nospam">Nospam value to create this Tox ID with.</param>
        public ToxId([NotNull] ToxKey publicKey, uint nospam)
        {
            if (publicKey.KeyType != ToxKeyType.Public)
            {
                throw new ArgumentException(nameof(publicKey));
            }

            byte[] id = new byte[ToxConstants.AddressSize];

            Array.Copy(publicKey.GetBytes(), 0, id, 0, ToxConstants.PublicKeySize);
            Array.Copy(BitConverter.GetBytes(nospam), 0, id, ToxConstants.PublicKeySize, ToxConstants.NospamSize);

            ushort checksum = CalculateChecksum(id, ToxConstants.PublicKeySize + ToxConstants.NospamSize);

            Array.Copy(BitConverter.GetBytes(checksum), 0, id, ToxConstants.PublicKeySize + ToxConstants.NospamSize, ToxConstants.ChecksumSize);

            this.id = id;
        }
Esempio n. 4
0
        /// <summary>
        /// Adds a friend to the friend list without sending a friend request.
        /// This method should be used to accept friend requests.
        /// </summary>
        /// <param name="publicKey">The public key of the friend to add.</param>
        /// <param name="error"></param>
        /// <returns>The friend number.</returns>
        public int AddFriendNoRequest(ToxKey publicKey, out ToxErrorFriendAdd error)
        {
            ThrowIfDisposed();

            if (publicKey == null)
                throw new ArgumentNullException("publicKey");

            error = ToxErrorFriendAdd.Ok;
            return (int)ToxFunctions.FriendAddNoRequest(_tox, publicKey.GetBytes(), ref error);
        }
Esempio n. 5
0
        /// <summary>
        /// Retrieves the friendNumber associated with the specified public key.
        /// </summary>
        /// <param name="publicKey">The public key to look for.</param>
        /// <param name="error"></param>
        /// <returns>The friend number on success.</returns>
        public int GetFriendByPublicKey(ToxKey publicKey, out ToxErrorFriendByPublicKey error)
        {
            ThrowIfDisposed();

            if (publicKey == null)
                throw new ArgumentNullException("publicKey");

            error = ToxErrorFriendByPublicKey.Ok;
            return (int)ToxFunctions.FriendByPublicKey(_tox, publicKey.GetBytes(), ref error);
        }