diff --git a/SimplePack/SimplePack.cs b/SimplePack/SimplePack.cs index 64ffbc0..8a4f937 100644 --- a/SimplePack/SimplePack.cs +++ b/SimplePack/SimplePack.cs @@ -1,5 +1,4 @@ -using System.Collections; -using Base58Check; +using Base58Check; namespace simplepack { @@ -9,20 +8,25 @@ namespace simplepack private string head; private string foot; public SimplePack(string header, string footer){ + // Specify human meaningful header/footer string head = header; foot = footer; + // header footer need to be >= 1 len if (header.Length == 0 | footer.Length == 0){ throw new InvalidSimplePackHeader(); } } public byte[] decode(string data){ + // Not valid if it doesn't have head/foot if (! data.Contains(head) | ! data.Contains(foot)){ throw new InvalidSimplePackHeader();} - string base58Data = ""; + + // Extract the encoded part without header/footer for (int i = head.Length; i < data.Length - foot.Length; i++){ base58Data += data[i]; } + // Will raise System.FormatException if checksum is not valid (or invalid footer/header) return Base58CheckEncoding.Decode(base58Data); }