acl_utils.adb 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. with Crypto.Types;
  2. with Crypto.Types.Base64;
  3. package body ACL_Utils is
  4. package CT renames Crypto.Types;
  5. function To_Base64 (Input: Integer) return Character is
  6. begin
  7. case Input is
  8. when 0 .. 25 => return Character'Val (Input - 0 + Character'Pos ('A')); -- A - Z
  9. when 26 .. 51 => return Character'Val (Input - 26 + Character'Pos ('a')); -- a - z
  10. when 52 .. 61 => return Character'Val (Input - 52 + Character'Pos ('0')); -- 0 - 9
  11. when 62 => return '+';
  12. when 63 => return '/';
  13. when Integer'Last => return '=';
  14. when others => raise CONSTRAINT_ERROR with "Got invalid input: " & Integer'Image (Input);
  15. end case;
  16. end To_Base64;
  17. function To_Base64 (Input: String) return String is
  18. package Base64i is new CT.Base64 (Integer);
  19. B64array : constant Base64i.Base64_String := Base64i.Encode_Base64 (CT.To_Bytes (Input));
  20. B64string : String (1 .. B64array'Length);
  21. begin
  22. -- convert to actual base64 characters
  23. for Index in B64array'Range loop
  24. B64string (Index) := To_Base64 (B64array (Index));
  25. end loop;
  26. return String(B64string);
  27. end To_Base64;
  28. end ACL_Utils;