12345678910111213141516171819202122232425262728293031323334353637 |
- with Crypto.Types;
- with Crypto.Types.Base64;
- package body ACL_Utils is
- package CT renames Crypto.Types;
- function To_Base64 (Input: Integer) return Character is
- begin
- case Input is
- when 0 .. 25 => return Character'Val (Input - 0 + Character'Pos ('A')); -- A - Z
- when 26 .. 51 => return Character'Val (Input - 26 + Character'Pos ('a')); -- a - z
- when 52 .. 61 => return Character'Val (Input - 52 + Character'Pos ('0')); -- 0 - 9
- when 62 => return '+';
- when 63 => return '/';
- when Integer'Last => return '=';
- when others => raise CONSTRAINT_ERROR with "Got invalid input: " & Integer'Image (Input);
- end case;
- end To_Base64;
-
-
- function To_Base64 (Input: String) return String is
- package Base64i is new CT.Base64 (Integer);
- B64array : constant Base64i.Base64_String := Base64i.Encode_Base64 (CT.To_Bytes (Input));
- B64string : String (1 .. B64array'Length);
- begin
- -- convert to actual base64 characters
- for Index in B64array'Range loop
- B64string (Index) := To_Base64 (B64array (Index));
- end loop;
- return String(B64string);
- end To_Base64;
- end ACL_Utils;
|