/// <summary>
        ///     Register the standard multi-base algorithms for IPFS.
        /// </summary>
        /// <seealso href="https://github.com/multiformats/multibase/blob/master/multibase.csv" />
        static MultiBaseAlgorithm()
        {
            Register("base58btc", 'z',
                     bytes => SimpleBase.Base58.Bitcoin.Encode(bytes),
                     s => SimpleBase.Base58.Bitcoin.Decode(s));
            Register("base58flickr", 'Z',
                     bytes => SimpleBase.Base58.Flickr.Encode(bytes),
                     s => SimpleBase.Base58.Flickr.Decode(s));
            Register("base64", 'm',
                     bytes => bytes.ToBase64NoPad(),
                     s => s.FromBase64NoPad());
            Register("base64pad", 'M',
                     bytes => Convert.ToBase64String(bytes),
                     s => Convert.FromBase64String(s));
            Register("base64url", 'u',
                     bytes => bytes.ToBase64Url(),
                     s => s.FromBase64Url());
            Register("base16", 'f',
                     bytes => Base16.EncodeLower(bytes),
                     s => Base16.Decode(s));
            Register("base32", 'b',
                     bytes => SimpleBase.Base32.Rfc4648.Encode(bytes, false).ToLowerInvariant(),
                     s => SimpleBase.Base32.Rfc4648.Decode(s));
            Register("base32pad", 'c',
                     bytes => SimpleBase.Base32.Rfc4648.Encode(bytes, true).ToLowerInvariant(),
                     s => SimpleBase.Base32.Rfc4648.Decode(s));
            Register("base32hex", 'v',
                     bytes => SimpleBase.Base32.ExtendedHex.Encode(bytes, false).ToLowerInvariant(),
                     s => SimpleBase.Base32.ExtendedHex.Decode(s));
            Register("base32hexpad", 't',
                     bytes => SimpleBase.Base32.ExtendedHex.Encode(bytes, true).ToLowerInvariant(),
                     s => SimpleBase.Base32.ExtendedHex.Decode(s));
            Register("BASE16", 'F',
                     bytes => Base16.EncodeUpper(bytes),
                     s => Base16.Decode(s));
            Register("BASE32", 'B',
                     bytes => SimpleBase.Base32.Rfc4648.Encode(bytes, false),
                     s => SimpleBase.Base32.Rfc4648.Decode(s));
            Register("BASE32PAD", 'C',
                     bytes => SimpleBase.Base32.Rfc4648.Encode(bytes, true),
                     s => SimpleBase.Base32.Rfc4648.Decode(s));
            Register("BASE32HEX", 'V',
                     bytes => SimpleBase.Base32.ExtendedHex.Encode(bytes, false),
                     s => SimpleBase.Base32.ExtendedHex.Decode(s));
            Register("BASE32HEXPAD", 'T',
                     bytes => SimpleBase.Base32.ExtendedHex.Encode(bytes, true),
                     s => SimpleBase.Base32.ExtendedHex.Decode(s));
            Register("base32z", 'h',
                     bytes => Base32z.Codec.Encode(bytes, false),
                     s => Base32z.Codec.Decode(s));

            // Not supported
#if false
            Register("base1", '1');
            Register("base2", '0');
            Register("base8", '7');
            Register("base10", '9');
#endif
        }
Example #2
0
        public void EncodeLower_Stream(byte[] input, string expectedOutput)
        {
            using var inputStream = new MemoryStream(input);
            using var writer      = new StringWriter();
#pragma warning disable CS0618 // Type or member is obsolete
            Base16.EncodeLower(inputStream, writer);
#pragma warning restore CS0618 // Type or member is obsolete
            Assert.AreEqual(expectedOutput, writer.ToString());
        }
        public DevDnsClient(IPeerSettings peerSettings)
        {
            _seedServers = peerSettings.SeedServers;

            _peerIds = Enumerable.Range(0, 5)
                       .Select(i => ByteUtil.GenerateRandomByteArray(32).BuildPeerIdFromPublicKey(IPAddress.Any, 1234));
            var peerIdsAsStrings = _peerIds.Select(p => Base16.EncodeLower(p.ToByteArray()));

            _dnsQueryAnswerValues = peerIdsAsStrings.ToArray();
        }
Example #4
0
        public void EncodeLower(byte[] input, string expectedOutput)
        {
            var result = Base16.EncodeLower(input);

            Assert.AreEqual(expectedOutput.ToLowerInvariant(), result);
        }
Example #5
0
        public void EncodeLower_Works()
        {
#pragma warning disable CS0618 // Type or member is obsolete
            Assert.AreEqual("abcd", Base16.EncodeLower(new byte[] { 0xAB, 0xCD }));
#pragma warning restore CS0618 // Type or member is obsolete
        }
Example #6
0
 /// <summary>
 ///   Write bytes encoded in base-16.
 /// </summary>
 /// <param name="value">
 ///   The value to write.
 /// </param>
 /// <param name="appendSpace">
 ///   Write a space after the value.
 /// </param>
 public void WriteBase16String(byte[] value, bool appendSpace = true)
 {
     WriteString(Base16.EncodeLower(value), appendSpace);
 }