Browse Source

Minor updates to PIP-0027 and UCommon.pas

Herman Schoenfeld 6 years ago
parent
commit
86727fc635
2 changed files with 15 additions and 10 deletions
  1. 3 3
      PIP/PIP-0027.md
  2. 12 7
      src/libraries/sphere10/UCommon.pas

+ 3 - 3
PIP/PIP-0027.md

@@ -42,7 +42,7 @@ An Extended PASA is defined by the below EBNF grammar:
     Password           = HexString                                             (* force passwords to be specified in hex *)
     Pascal64String     = Pascal64StartChar, { Pascal64Char } ;
     Pascal64StartChar  ??= TODO
-    Pascal64Char       ??=  TODO
+    Pascal64Char       ??= TODO
     HexString          = "0", "x", HexByte { HexByte } ;
     HexByte            = HexDigit, HexDigit
     HexDigit           = ( Digit | "a" | "b" | "c" | "d" | "e" | "f" ) ;       (* no uppercase hex allowed *)
@@ -76,7 +76,7 @@ An Extended PASA is defined by the below EBNF grammar:
 In order to avoid data entry errors, the payload portion is **optionally** checksummed. The payload checksum is calculated as follows:
 
 ```
-    PayloadChecksum = ToHexString( MurMur3( PayloadEncType ++ Payload ) MOD 65536 )
+    PayloadChecksum = ToHexString ( CastToUINT16( MurMur3( PayloadEncType ++ Payload ) MOD 65536 ) )
 
     PayloadEncType  = "0" for PublicPayload
                     = "1" for ReceiverEncPayload
@@ -127,7 +127,7 @@ The design approach was to remain backwards compatible in order to allow existin
 
 ## Backwards Compatibility
 
-This PIP is backwards compatible and does not requier a hard-fork activation, only an implementation change.
+This PIP is backwards compatible and does not require a hard-fork activation, only an implementation change.
 
 ## Reference Implementation
 

+ 12 - 7
src/libraries/sphere10/UCommon.pas

@@ -42,10 +42,13 @@ const
 
 { GLOBAL HELPER FUNCTIONS }
 
+
 function String2Hex(const Buffer: String): String;
-//function Hex2Bytes(const AHexString: String): TBytes; overload;
-//function TryHex2Bytes(const AHexString: String; out ABytes : TBytes): boolean; overload;
+function Hex2Bytes(const AHexString: String): TBytes; overload;
+{$IFDEF UNITTESTS}
+function TryHex2Bytes(const AHexString: String; out ABytes : TBytes): boolean; overload;
 function Bytes2Hex(const ABytes: TBytes; AUsePrefix : boolean = false) : String;
+{$ENDIF}
 function BinStrComp(const Str1, Str2 : String): Integer; // Binary-safe StrComp replacement. StrComp will return 0 for when str1 and str2 both start with NUL character.
 function BytesCompare(const ABytes1, ABytes2: TBytes): integer;
 function BytesEqual(const ABytes1, ABytes2 : TBytes) : boolean; inline;
@@ -442,13 +445,14 @@ begin
     Result := AnsiLowerCase(Result + IntToHex(Ord(Buffer[n]), 2));
 end;
 
-{function Hex2Bytes(const AHexString: String): TBytes;
+{$IFDEF UNITTESTS}
+function Hex2Bytes(const AHexString: String): TBytes;
 begin
   if NOT TryHex2Bytes(AHexString, Result) then
     raise EArgumentOutOfRangeException.Create('Invalidly formatted hexadecimal string.');
 end;
-}
-{function TryHex2Bytes(const AHexString: String; out ABytes : TBytes): boolean; overload;
+
+function TryHex2Bytes(const AHexString: String; out ABytes : TBytes): boolean; overload;
 var
   P : PAnsiChar;
   LHexString : String;
@@ -457,7 +461,7 @@ begin
   SetLength(ABytes, 0);
   LHexLength := System.Length(AHexString);
   LHexStart := 1;
-  if {$IFDEF FPCAnsiStartsText{$ELSEStartsText{$ENDIF('0x', AHexString) then begin
+  if {$IFDEF FPC}AnsiStartsText{$ELSE}StartsText{$ENDIF}('0x', AHexString) then begin
 
     // Special case: 0x0 = empty byte array
     if (LHexLength = 3) AND (AHexString[3] = '0') then
@@ -477,7 +481,8 @@ begin
   LHexString := LowerCase(AHexString);
   LHexIndex := HexToBin(PAnsiChar(@LHexString[LHexStart]), P, System.Length(ABytes));
   Result := (LHexIndex = (LHexLength DIV 2));
-end;}
+end;
+{$ENDIF}
 
 function Bytes2Hex(const ABytes: TBytes; AUsePrefix : boolean = false) : String;
 var