added comments
This commit is contained in:
parent
70957e5ab2
commit
8cc8889f39
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user