コード例 #1
0
        /// <summary>
        /// Decodes and decrypts the dns3 string returned by <see cref="GenerateDns3String"/>.
        /// </summary>
        /// <param name="dns3String">String to decrypt.</param>
        /// <param name="requestId">The request id retrieved with GenerateDns3String.</param>
        /// <returns></returns>
        public string DecryptDns3TXT(string dns3String, int requestId)
        {
            ThrowIfDisposed();

            byte[] id            = new byte[ToxConstants.AddressSize];
            byte[] idRecordBytes = Encoding.UTF8.GetBytes(dns3String);

            int result = ToxDnsFunctions.DecryptDns3TXT(_toxDns3, id, idRecordBytes, (uint)idRecordBytes.Length, ToxTools.Map(requestId));

            if (result == 0)
            {
                return(ToxTools.HexBinToString(id));
            }
            else
            {
                throw new Exception("Could not decrypt and decode id_record");
            }
        }
コード例 #2
0
ファイル: ToxDns.cs プロジェクト: logicethos/SharpTox
        /// <summary>
        /// Decodes and decrypts the dns3 string returned by <see cref="GenerateDns3String"/>.
        /// </summary>
        /// <param name="dns3String"></param>
        /// <param name="requestId"></param>
        /// <returns></returns>
        public string DecryptDns3TXT(string dns3String, uint requestId)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException(GetType().FullName);
            }

            byte[] id            = new byte[32 + sizeof(uint) + sizeof(ushort)];
            byte[] idRecordBytes = Encoding.UTF8.GetBytes(dns3String);

            int result = ToxDnsFunctions.DecryptDns3TXT(_toxDns3, id, idRecordBytes, (uint)idRecordBytes.Length, (uint)requestId);

            if (result == 0)
            {
                return(ToxTools.HexBinToString(id));
            }
            else
            {
                throw new Exception("Could not decrypt and decode id_record");
            }
        }
コード例 #3
0
        public void HexBinToString_Result_AreEqual(byte[] input, string expected)
        {
            var result = ToxTools.HexBinToString(input);

            Assert.AreEqual(expected, result);
        }
コード例 #4
0
 /// <summary>
 /// Retrieves a string of the tox key.
 /// </summary>
 /// <returns></returns>
 public string GetString()
 {
     return(ToxTools.HexBinToString(key));
 }
コード例 #5
0
        public void IsValid_ValidIdString_IsTrue()
        {
            var result = ToxId.IsValid(ToxTools.HexBinToString(this.validTestId));

            Assert.IsTrue(result);
        }
コード例 #6
0
 public void Constructor_InvalidChecksumString_ArgumentException()
 {
     Assert.Throws <ArgumentException>(() => new ToxId(ToxTools.HexBinToString(this.invalidTestId)));
 }