added comments

This commit is contained in:
Kevin Froman 2020-05-27 01:52:48 -05:00
parent 70957e5ab2
commit 8cc8889f39
No known key found for this signature in database
GPG Key ID: BF1CE85F428B8CE3

View File

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