diff --git a/src/Bofa.bf b/src/Bofa.bf index 58b2626..aeb0277 100644 --- a/src/Bofa.bf +++ b/src/Bofa.bf @@ -92,9 +92,11 @@ class Bofa } case .RGB: - strBuffer.Append(scope $"rgb {Name} {Value.Rgb[0]:X2)} {Value.Rgb[1]:X2)} {Value.Rgb[2]:X2)}"); + strBuffer.Append(scope $"rgb {Name} {Value.Rgb[0]:X2} {Value.Rgb[1]:X2} {Value.Rgb[2]:X2}"); case .RGBA: - strBuffer.Append(scope $"rgb {Name} {Value.Rgba[0]:X2)} {Value.Rgba[1]:X2)} {Value.Rgba[2]:X2)} {Value.Rgba[3]:X2)}"); + strBuffer.Append(scope $"rgb {Name} {Value.Rgba[0]:X2} {Value.Rgba[1]:X2} {Value.Rgba[2]:X2} {Value.Rgba[3]:X2}"); + case .Hash: + strBuffer.Append(scope $"hash {Name} sha256-{Value.Hash}"); } } diff --git a/src/BofaParser.bf b/src/BofaParser.bf index 9bed856..b4fae7a 100644 --- a/src/BofaParser.bf +++ b/src/BofaParser.bf @@ -182,6 +182,8 @@ class BofaParser typeName = "RBG"; case "rgba": typeName = "RBGA"; + case "hash": + typeName = "Hash"; default: toReturn.Type = .Error; return toReturn; //Unsupported type error @@ -328,6 +330,15 @@ class BofaParser return toReturn; } bofaRes.Value.Rgba = result.Value; + case "hash": + bofaRes.Type = .Hash; + var result = AdditionalParsers.ParseHash(line); + if(result case .Err) + { + toReturn.Type = .Error; + return toReturn; + } + bofaRes.Value.Hash = result.Value; default: //Unknown type toReturn.Type = .Error; return toReturn; diff --git a/src/BofaValue.bf b/src/BofaValue.bf index b748d84..48bbe85 100644 --- a/src/BofaValue.bf +++ b/src/BofaValue.bf @@ -2,6 +2,7 @@ namespace Bofa; using System; using System.Collections; +using System.Security.Cryptography; [Union] struct BofaValue @@ -20,4 +21,5 @@ struct BofaValue public List Array; public uint8[3] Rgb; public uint8[4] Rgba; + public SHA256Hash Hash; } \ No newline at end of file diff --git a/src/Parser/AdditionalParsers.bf b/src/Parser/AdditionalParsers.bf index a812c3a..e244647 100644 --- a/src/Parser/AdditionalParsers.bf +++ b/src/Parser/AdditionalParsers.bf @@ -1,6 +1,7 @@ namespace Bofa.Parser; using System; +using System.Security.Cryptography; class AdditionalParsers { @@ -40,4 +41,17 @@ class AdditionalParsers return .Ok(toReturn); } + public static Result ParseHash(StringView pValue) + { + //We currently dont support more than sha256 as hashing algorithms + if(pValue.Contains('-') && !pValue.StartsWith("sha256-")) + return .Err; + + var pValue; + if(pValue.StartsWith("sha256-")) + pValue = pValue.Substring("sha256-".Length); + + return SHA256Hash.Parse(pValue); + } + } \ No newline at end of file diff --git a/src/Testing/Default.bf b/src/Testing/Default.bf index 818856e..898cf14 100644 --- a/src/Testing/Default.bf +++ b/src/Testing/Default.bf @@ -32,12 +32,13 @@ class Default # 1.1.0 rgba color FF FF FF FF rgb c 34 67 EF + hash id sha256-218989F4E69B157EA38EBFC3051FB7A0011FBD1B2E4303DCB48D46C10622DA0B """; Dictionary output = new .(); List errors = new .(); BofaParser.Parse(content, output, errors); - Test.Assert(output.Count == 11); + Test.Assert(output.Count == 12); Test.Assert(errors.Count == 0); DeleteDictionaryAndValues!(output); diff --git a/src/eBofaType.bf b/src/eBofaType.bf index 595f66e..d4dc1d7 100644 --- a/src/eBofaType.bf +++ b/src/eBofaType.bf @@ -17,5 +17,6 @@ enum EBofaType //1.1.0 RGB, //3 * 8bit - RGBA //4 * 8bit + RGBA, //4 * 8bit + Hash, //Sha256 } \ No newline at end of file