Browse Source

sync with parent repo.

Ugochukwu Mmaduekwe 6 years ago
parent
commit
16a218191e

+ 20 - 0
src/libraries/cryptolib4pascal/ClpConverters.pas

@@ -292,44 +292,64 @@ end;
 class function TConverters.ReadBytesAsUInt32LE(a_in: PByte;
 class function TConverters.ReadBytesAsUInt32LE(a_in: PByte;
   a_index: Int32): UInt32;
   a_index: Int32): UInt32;
 begin
 begin
+{$IFDEF FPC}
 {$IFDEF FPC_REQUIRES_PROPER_ALIGNMENT}
 {$IFDEF FPC_REQUIRES_PROPER_ALIGNMENT}
   System.Move(a_in[a_index], result, System.SizeOf(UInt32));
   System.Move(a_in[a_index], result, System.SizeOf(UInt32));
 {$ELSE}
 {$ELSE}
   result := PCardinal(a_in + a_index)^;
   result := PCardinal(a_in + a_index)^;
 {$ENDIF FPC_REQUIRES_PROPER_ALIGNMENT}
 {$ENDIF FPC_REQUIRES_PROPER_ALIGNMENT}
+{$ELSE}
+  // Delphi does not handle unaligned memory access on ARM Devices properly.
+  System.Move(a_in[a_index], result, System.SizeOf(UInt32));
+{$ENDIF FPC}
   result := le2me_32(result);
   result := le2me_32(result);
 end;
 end;
 
 
 class function TConverters.ReadBytesAsUInt32BE(a_in: PByte;
 class function TConverters.ReadBytesAsUInt32BE(a_in: PByte;
   a_index: Int32): UInt32;
   a_index: Int32): UInt32;
 begin
 begin
+{$IFDEF FPC}
 {$IFDEF FPC_REQUIRES_PROPER_ALIGNMENT}
 {$IFDEF FPC_REQUIRES_PROPER_ALIGNMENT}
   System.Move(a_in[a_index], result, System.SizeOf(UInt32));
   System.Move(a_in[a_index], result, System.SizeOf(UInt32));
 {$ELSE}
 {$ELSE}
   result := PCardinal(a_in + a_index)^;
   result := PCardinal(a_in + a_index)^;
 {$ENDIF FPC_REQUIRES_PROPER_ALIGNMENT}
 {$ENDIF FPC_REQUIRES_PROPER_ALIGNMENT}
+{$ELSE}
+  // Delphi does not handle unaligned memory access on ARM Devices properly.
+  System.Move(a_in[a_index], result, System.SizeOf(UInt32));
+{$ENDIF FPC}
   result := be2me_32(result);
   result := be2me_32(result);
 end;
 end;
 
 
 class function TConverters.ReadBytesAsUInt64LE(a_in: PByte;
 class function TConverters.ReadBytesAsUInt64LE(a_in: PByte;
   a_index: Int32): UInt64;
   a_index: Int32): UInt64;
 begin
 begin
+{$IFDEF FPC}
 {$IFDEF FPC_REQUIRES_PROPER_ALIGNMENT}
 {$IFDEF FPC_REQUIRES_PROPER_ALIGNMENT}
   System.Move(a_in[a_index], result, System.SizeOf(UInt64));
   System.Move(a_in[a_index], result, System.SizeOf(UInt64));
 {$ELSE}
 {$ELSE}
   result := PUInt64(a_in + a_index)^;
   result := PUInt64(a_in + a_index)^;
 {$ENDIF FPC_REQUIRES_PROPER_ALIGNMENT}
 {$ENDIF FPC_REQUIRES_PROPER_ALIGNMENT}
+{$ELSE}
+  // Delphi does not handle unaligned memory access on ARM Devices properly.
+  System.Move(a_in[a_index], result, System.SizeOf(UInt64));
+{$ENDIF FPC}
   result := le2me_64(result);
   result := le2me_64(result);
 end;
 end;
 
 
 class function TConverters.ReadBytesAsUInt64BE(a_in: PByte;
 class function TConverters.ReadBytesAsUInt64BE(a_in: PByte;
   a_index: Int32): UInt64;
   a_index: Int32): UInt64;
 begin
 begin
+{$IFDEF FPC}
 {$IFDEF FPC_REQUIRES_PROPER_ALIGNMENT}
 {$IFDEF FPC_REQUIRES_PROPER_ALIGNMENT}
   System.Move(a_in[a_index], result, System.SizeOf(UInt64));
   System.Move(a_in[a_index], result, System.SizeOf(UInt64));
 {$ELSE}
 {$ELSE}
   result := PUInt64(a_in + a_index)^;
   result := PUInt64(a_in + a_index)^;
 {$ENDIF FPC_REQUIRES_PROPER_ALIGNMENT}
 {$ENDIF FPC_REQUIRES_PROPER_ALIGNMENT}
+{$ELSE}
+  // Delphi does not handle unaligned memory access on ARM Devices properly.
+  System.Move(a_in[a_index], result, System.SizeOf(UInt64));
+{$ENDIF FPC}
   result := be2me_64(result);
   result := be2me_64(result);
 end;
 end;
 
 

+ 0 - 1
src/libraries/cryptolib4pascal/ClpOSRandom.pas

@@ -199,7 +199,6 @@ end;
 class function TOSRandom.GenRandomBytesIOSDelphi(len: Int32;
 class function TOSRandom.GenRandomBytesIOSDelphi(len: Int32;
   const data: PByte): Int32;
   const data: PByte): Int32;
 begin
 begin
-  // UNTESTED !!!, Please Take Note.
   result := SecRandomCopyBytes(kSecRandomDefault, LongWord(len), data);
   result := SecRandomCopyBytes(kSecRandomDefault, LongWord(len), data);
 end;
 end;
 
 

+ 3 - 3
src/libraries/cryptolib4pascal/CryptoLibHelper.inc

@@ -19,8 +19,8 @@
 {$IFDEF ENDIAN_BIG}
 {$IFDEF ENDIAN_BIG}
 {$MESSAGE FATAL 'This Library does not support "Big Endian" processors yet.'}
 {$MESSAGE FATAL 'This Library does not support "Big Endian" processors yet.'}
 {$ENDIF}
 {$ENDIF}
-// FPC 3.0.0 and Above
+// FPC 3.0.4 and Above
 // Had to Include this here since Delphi does not allow it Compile in "CryptoLib.inc".
 // Had to Include this here since Delphi does not allow it Compile in "CryptoLib.inc".
-{$IF FPC_FULLVERSION < 30000}
-{$MESSAGE ERROR 'This Library requires FreePascal 3.0.0 or higher.'}
+{$IF FPC_FULLVERSION < 30004}
+{$MESSAGE ERROR 'This Library requires FreePascal 3.0.4 or higher.'}
 {$IFEND}
 {$IFEND}

+ 1 - 0
src/libraries/simplebaselib4pascal/SbpBase16.pas

@@ -92,6 +92,7 @@ begin
   end;
   end;
   if ((textLen and 1) <> 0) then
   if ((textLen and 1) <> 0) then
   begin
   begin
+    Ltext := '';
     if System.Length(text) > 0 then
     if System.Length(text) > 0 then
     begin
     begin
       System.SetString(Ltext, PChar(@text[0]), System.Length(text));
       System.SetString(Ltext, PChar(@text[0]), System.Length(text));

+ 33 - 30
src/libraries/simplebaselib4pascal/SbpBase85.pas

@@ -15,7 +15,7 @@ uses
 resourcestring
 resourcestring
   SAlphabetNil = 'Alphabet Instance cannot be Nil "%s"';
   SAlphabetNil = 'Alphabet Instance cannot be Nil "%s"';
   SUnExpectedCharacter =
   SUnExpectedCharacter =
-    'Unexpected Character "%s" In The Middle Of a Regular Block';
+    'Unexpected Shortcut Character In The Middle Of a Regular Block';
 
 
 type
 type
   TBase85 = class sealed(TInterfacedObject, IBase85)
   TBase85 = class sealed(TInterfacedObject, IBase85)
@@ -35,7 +35,7 @@ type
       numBytesToWrite: Int32); static; inline;
       numBytesToWrite: Int32); static; inline;
 
 
     class procedure WriteShortcut(var pOutput: PByte; blockIndex: Int32;
     class procedure WriteShortcut(var pOutput: PByte; blockIndex: Int32;
-      c: Char; value: Int64); static; inline;
+      value: Int64); static; inline;
 
 
     class function GetDecodeBufferLength(textLen: Int32;
     class function GetDecodeBufferLength(textLen: Int32;
       usingShortcuts: Boolean): Int32; static; inline;
       usingShortcuts: Boolean): Int32; static; inline;
@@ -57,7 +57,8 @@ type
       : TSimpleBaseLibByteArray; overload;
       : TSimpleBaseLibByteArray; overload;
 
 
     procedure WriteOutput(var pOutput: PChar; const table: String; input: Int64;
     procedure WriteOutput(var pOutput: PChar; const table: String; input: Int64;
-      stringLength: Int32; hasShortcut: Boolean); inline;
+      stringLength: Int32; usesZeroShortcut, usesSpaceShortcut
+      : Boolean); inline;
 
 
   public
   public
 
 
@@ -94,27 +95,27 @@ implementation
 { TBase85 }
 { TBase85 }
 
 
 procedure TBase85.WriteOutput(var pOutput: PChar; const table: String;
 procedure TBase85.WriteOutput(var pOutput: PChar; const table: String;
-  input: Int64; stringLength: Int32; hasShortcut: Boolean);
+  input: Int64; stringLength: Int32; usesZeroShortcut, usesSpaceShortcut
+  : Boolean);
 var
 var
   i: Int32;
   i: Int32;
   result: Int64;
   result: Int64;
 begin
 begin
-  // handle "z" shortcut
-  if (hasShortcut) then
+  // handle shortcuts
+  if (input = 0) and (usesZeroShortcut) then
   begin
   begin
-    if (input = 0) then
-    begin
-      pOutput^ := Falphabet.AllZeroShortcut;
-      System.Inc(pOutput);
-      Exit;
-    end;
-    if (input = allSpace) then
-    begin
-      pOutput^ := Falphabet.AllSpaceShortcut;
-      System.Inc(pOutput);
-      Exit;
-    end;
+    pOutput^ := Falphabet.AllZeroShortcut;
+    System.Inc(pOutput);
+    Exit;
   end;
   end;
+
+  if (input = allSpace) and (usesSpaceShortcut) then
+  begin
+    pOutput^ := Falphabet.AllSpaceShortcut;
+    System.Inc(pOutput);
+    Exit;
+  end;
+
   // map the 4-byte packet to to 5-byte octets
   // map the 4-byte packet to to 5-byte octets
   i := stringBlockSize - 1;
   i := stringBlockSize - 1;
   while i >= 0 do
   while i >= 0 do
@@ -146,12 +147,11 @@ begin
 end;
 end;
 
 
 class procedure TBase85.WriteShortcut(var pOutput: PByte; blockIndex: Int32;
 class procedure TBase85.WriteShortcut(var pOutput: PByte; blockIndex: Int32;
-  c: Char; value: Int64);
+  value: Int64);
 begin
 begin
   if (blockIndex <> 0) then
   if (blockIndex <> 0) then
   begin
   begin
-    raise EArgumentSimpleBaseLibException.CreateResFmt
-      (@SUnExpectedCharacter, [c]);
+    raise EArgumentSimpleBaseLibException.CreateRes(@SUnExpectedCharacter);
   end;
   end;
   WriteDecodedValue(pOutput, value, byteBlockSize);
   WriteDecodedValue(pOutput, value, byteBlockSize);
 end;
 end;
@@ -204,8 +204,8 @@ begin
   end;
   end;
   allZeroChar := Falphabet.AllZeroShortcut;
   allZeroChar := Falphabet.AllZeroShortcut;
   allSpaceChar := Falphabet.AllSpaceShortcut;
   allSpaceChar := Falphabet.AllSpaceShortcut;
-  checkZero := allZeroChar <> TBase85Alphabet.NoShortcut;
-  checkSpace := allSpaceChar <> TBase85Alphabet.NoShortcut;
+  checkZero := allZeroChar <> TBase85Alphabet.NullChar;
+  checkSpace := allSpaceChar <> TBase85Alphabet.NullChar;
   usingShortcuts := checkZero or checkSpace;
   usingShortcuts := checkZero or checkSpace;
   // allocate a larger buffer if we're using shortcuts
   // allocate a larger buffer if we're using shortcuts
 
 
@@ -234,12 +234,12 @@ begin
     // handle shortcut characters
     // handle shortcut characters
     if ((checkZero) and (c = allZeroChar)) then
     if ((checkZero) and (c = allZeroChar)) then
     begin
     begin
-      WriteShortcut(pDecodeBuffer, blockIndex, allZeroChar, 0);
+      WriteShortcut(pDecodeBuffer, blockIndex, 0);
       continue;
       continue;
     end;
     end;
     if ((checkSpace) and (c = allSpaceChar)) then
     if ((checkSpace) and (c = allSpaceChar)) then
     begin
     begin
-      WriteShortcut(pDecodeBuffer, blockIndex, allSpaceChar, allSpace);
+      WriteShortcut(pDecodeBuffer, blockIndex, allSpace);
       continue;
       continue;
     end;
     end;
 
 
@@ -298,7 +298,7 @@ var
   bytesLen, maxOutputLen, fullLen, remainingBytes, n, outputLen: Int32;
   bytesLen, maxOutputLen, fullLen, remainingBytes, n, outputLen: Int32;
   input: Int64;
   input: Int64;
   t1, t2, t3, t4: UInt32;
   t1, t2, t3, t4: UInt32;
-  hasShortcut: Boolean;
+  usesZeroShortcut, usesSpaceShortcut: Boolean;
   output: TSimpleBaseLibCharArray;
   output: TSimpleBaseLibCharArray;
   table: string;
   table: string;
   inputPtr, pInput, pInputEnd: PByte;
   inputPtr, pInput, pInputEnd: PByte;
@@ -310,7 +310,8 @@ begin
   begin
   begin
     Exit;
     Exit;
   end;
   end;
-  hasShortcut := Falphabet.hasShortcut;
+  usesZeroShortcut := Falphabet.AllZeroShortcut <> TBase85Alphabet.NullChar;
+  usesSpaceShortcut := Falphabet.AllSpaceShortcut <> TBase85Alphabet.NullChar;
 
 
   // adjust output length based on prefix and suffix settings
   // adjust output length based on prefix and suffix settings
   // we know output length is too large but we will handle it later.
   // we know output length is too large but we will handle it later.
@@ -339,10 +340,11 @@ begin
     t4 := (UInt32(pInput^));
     t4 := (UInt32(pInput^));
     System.Inc(pInput);
     System.Inc(pInput);
     input := t1 or t2 or t3 or t4;
     input := t1 or t2 or t3 or t4;
-    WriteOutput(pOutput, table, input, stringBlockSize, hasShortcut);
+    WriteOutput(pOutput, table, input, stringBlockSize, usesZeroShortcut,
+      usesSpaceShortcut);
   end;
   end;
 
 
-  // remaining part?
+  // check if a part is remaining
   remainingBytes := bytesLen - fullLen;
   remainingBytes := bytesLen - fullLen;
   if (remainingBytes > 0) then
   if (remainingBytes > 0) then
   begin
   begin
@@ -355,7 +357,8 @@ begin
       System.Inc(n);
       System.Inc(n);
     end;
     end;
 
 
-    WriteOutput(pOutput, table, input, remainingBytes + 1, hasShortcut);
+    WriteOutput(pOutput, table, input, remainingBytes + 1, usesZeroShortcut,
+      usesSpaceShortcut);
   end;
   end;
 
 
   outputLen := Int32(pOutput - outputPtr);
   outputLen := Int32(pOutput - outputPtr);

+ 23 - 11
src/libraries/simplebaselib4pascal/SbpBase85Alphabet.pas

@@ -15,7 +15,7 @@ type
   strict private
   strict private
 
 
   const
   const
-    No_Shortcut = Char($FFFF);
+    Null_Char = Char(0);
 
 
   var
   var
     FAllZeroShortcut, FAllSpaceShortcut: Char;
     FAllZeroShortcut, FAllSpaceShortcut: Char;
@@ -28,7 +28,8 @@ type
     function GetAllSpaceShortcut: Char; inline;
     function GetAllSpaceShortcut: Char; inline;
     function GetAllZeroShortcut: Char; inline;
     function GetAllZeroShortcut: Char; inline;
 
 
-    class function GetNoShortcut: Char; static; inline;
+    class function GetNullChar: Char; static; inline;
+
     class function GetZ85: IBase85Alphabet; static; inline;
     class function GetZ85: IBase85Alphabet; static; inline;
     class function GetAscii85: IBase85Alphabet; static; inline;
     class function GetAscii85: IBase85Alphabet; static; inline;
 
 
@@ -36,26 +37,37 @@ type
 
 
   public
   public
 
 
+    /// <summary>
+    /// Gets a value indicating whether the alphabet uses one of shortcut characters for all spaces
+    /// or all zeros.
+    /// </summary>
     property HasShortcut: Boolean read GetHasShortcut;
     property HasShortcut: Boolean read GetHasShortcut;
+
+    /// <summary>
+    /// Gets the character to be used for "all zeros"
+    /// </summary>
+
     property AllZeroShortcut: Char read GetAllZeroShortcut;
     property AllZeroShortcut: Char read GetAllZeroShortcut;
+    /// <summary>
+    /// Gets the character to be used for "all spaces"
+    /// </summary>
     property AllSpaceShortcut: Char read GetAllSpaceShortcut;
     property AllSpaceShortcut: Char read GetAllSpaceShortcut;
 
 
-    class property NoShortcut: Char read GetNoShortcut;
-
     /// <summary>
     /// <summary>
-    /// ZeroMQ Z85 Alphabet
+    /// Gets ZeroMQ Z85 Alphabet
     /// </summary>
     /// </summary>
     class property Z85: IBase85Alphabet read GetZ85;
     class property Z85: IBase85Alphabet read GetZ85;
 
 
     /// <summary>
     /// <summary>
-    /// Adobe Ascii85 Alphabet (each character is directly produced by raw
+    /// Get Adobe Ascii85 Alphabet (each character is directly produced by raw
     /// value + 33)
     /// value + 33)
     /// </summary>
     /// </summary>
     class property Ascii85: IBase85Alphabet read GetAscii85;
     class property Ascii85: IBase85Alphabet read GetAscii85;
 
 
+    class property NullChar: Char read GetNullChar;
+
     constructor Create(const alphabet: String;
     constructor Create(const alphabet: String;
-      AllZeroShortcut: Char = No_Shortcut;
-      AllSpaceShortcut: Char = No_Shortcut);
+      AllZeroShortcut: Char = Null_Char; AllSpaceShortcut: Char = Null_Char);
     destructor Destroy; override;
     destructor Destroy; override;
   end;
   end;
 
 
@@ -95,14 +107,14 @@ begin
   Result := FAllZeroShortcut;
   Result := FAllZeroShortcut;
 end;
 end;
 
 
-class function TBase85Alphabet.GetNoShortcut: Char;
+class function TBase85Alphabet.GetNullChar: Char;
 begin
 begin
-  Result := No_Shortcut;
+  Result := Null_Char;
 end;
 end;
 
 
 function TBase85Alphabet.GetHasShortcut: Boolean;
 function TBase85Alphabet.GetHasShortcut: Boolean;
 begin
 begin
-  Result := (AllSpaceShortcut <> NoShortcut) or (AllZeroShortcut <> NoShortcut);
+  Result := (AllSpaceShortcut <> NullChar) or (AllZeroShortcut <> NullChar);
 end;
 end;
 
 
 class function TBase85Alphabet.GetZ85: IBase85Alphabet;
 class function TBase85Alphabet.GetZ85: IBase85Alphabet;

+ 12 - 0
src/libraries/simplebaselib4pascal/SbpIBase85Alphabet.pas

@@ -15,8 +15,20 @@ type
     function GetAllSpaceShortcut: Char;
     function GetAllSpaceShortcut: Char;
     function GetAllZeroShortcut: Char;
     function GetAllZeroShortcut: Char;
 
 
+    /// <summary>
+    /// Gets a value indicating whether the alphabet uses one of shortcut characters for all spaces
+    /// or all zeros.
+    /// </summary>
     property HasShortcut: Boolean read GetHasShortcut;
     property HasShortcut: Boolean read GetHasShortcut;
+
+    /// <summary>
+    /// Gets the character to be used for "all zeros"
+    /// </summary>
+
     property AllZeroShortcut: Char read GetAllZeroShortcut;
     property AllZeroShortcut: Char read GetAllZeroShortcut;
+    /// <summary>
+    /// Gets the character to be used for "all spaces"
+    /// </summary>
     property AllSpaceShortcut: Char read GetAllSpaceShortcut;
     property AllSpaceShortcut: Char read GetAllSpaceShortcut;
 
 
   end;
   end;