You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

base64.h 987B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #ifndef _IPXE_BASE64_H
  2. #define _IPXE_BASE64_H
  3. /** @file
  4. *
  5. * Base64 encoding
  6. *
  7. */
  8. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  9. #include <stdint.h>
  10. #include <string.h>
  11. /**
  12. * Calculate length of base64-encoded data
  13. *
  14. * @v raw_len Raw data length
  15. * @ret encoded_len Encoded string length (excluding NUL)
  16. */
  17. static inline size_t base64_encoded_len ( size_t raw_len ) {
  18. return ( ( ( raw_len + 3 - 1 ) / 3 ) * 4 );
  19. }
  20. /**
  21. * Calculate maximum length of base64-decoded string
  22. *
  23. * @v encoded Encoded string
  24. * @v max_raw_len Maximum length of raw data
  25. *
  26. * Note that the exact length of the raw data cannot be known until
  27. * the string is decoded.
  28. */
  29. static inline size_t base64_decoded_max_len ( const char *encoded ) {
  30. return ( ( ( strlen ( encoded ) + 4 - 1 ) / 4 ) * 3 );
  31. }
  32. extern size_t base64_encode ( const void *raw, size_t raw_len, char *data,
  33. size_t len );
  34. extern int base64_decode ( const char *encoded, void *data, size_t len );
  35. #endif /* _IPXE_BASE64_H */