public void Base58_Encode_Decode() { var mh = new MultiHash("QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB"); Assert.AreEqual("sha2-256", mh.Algorithm.Name); Assert.AreEqual(32, mh.Digest.Length); Assert.AreEqual("QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB", mh.ToBase58()); }
/// <summary> /// Converts the CID to its equivalent string representation. /// </summary> /// <returns> /// The string representation of the <see cref="Cid"/>. /// </returns> /// <remarks> /// For <see cref="Version"/> 0, this is equalivalent to the /// <see cref="MultiHash.ToBase58()">base58btc encoding</see> /// of the <see cref="Hash"/>. /// </remarks> /// <seealso cref="Decode"/> public string Encode() { if (Version == 0) { return(Hash.ToBase58()); } using (var ms = new MemoryStream()) { ms.WriteVarint(Version); ms.WriteMultiCodec(ContentType); Hash.Write(ms); return(MultiBase.Encode(ms.ToArray(), Encoding)); } }
/// <summary> /// Converts the CID to its equivalent string representation. /// </summary> /// <returns> /// The string representation of the <see cref="Cid"/>. /// </returns> /// <remarks> /// For <see cref="Version"/> 0, this is equalivalent to the /// <see cref="MultiHash.ToBase58()">base58btc encoding</see> /// of the <see cref="Hash"/>. /// </remarks> /// <seealso cref="Decode"/> public string Encode() { if (encodedValue != null) { return(encodedValue); } if (Version == 0) { encodedValue = Hash.ToBase58(); } else { using (var ms = new MemoryStream()) { ms.WriteVarint(Version); ms.WriteMultiCodec(ContentType); Hash.Write(ms); encodedValue = MultiBase.Encode(ms.ToArray(), Encoding); } } return(encodedValue); }
public override void ReadValue(CodedInputStream stream) { stream.ReadLength(); MultiHash = new MultiHash(stream); Value = MultiHash.ToBase58(); }