|
@@ -33,23 +33,24 @@ static const char base64[64] =
|
33
|
33
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
34
|
34
|
|
35
|
35
|
/**
|
36
|
|
- * Base64-encode a string
|
|
36
|
+ * Base64-encode data
|
37
|
37
|
*
|
38
|
|
- * @v raw Raw string
|
|
38
|
+ * @v raw Raw data
|
|
39
|
+ * @v len Length of raw data
|
39
|
40
|
* @v encoded Buffer for encoded string
|
40
|
41
|
*
|
41
|
42
|
* The buffer must be the correct length for the encoded string. Use
|
42
|
43
|
* something like
|
43
|
44
|
*
|
44
|
|
- * char buf[ base64_encoded_len ( strlen ( raw ) ) + 1 ];
|
|
45
|
+ * char buf[ base64_encoded_len ( len ) + 1 ];
|
45
|
46
|
*
|
46
|
47
|
* (the +1 is for the terminating NUL) to provide a buffer of the
|
47
|
48
|
* correct size.
|
48
|
49
|
*/
|
49
|
|
-void base64_encode ( const char *raw, char *encoded ) {
|
|
50
|
+void base64_encode ( const uint8_t *raw, size_t len, char *encoded ) {
|
50
|
51
|
const uint8_t *raw_bytes = ( ( const uint8_t * ) raw );
|
51
|
52
|
uint8_t *encoded_bytes = ( ( uint8_t * ) encoded );
|
52
|
|
- size_t raw_bit_len = ( 8 * strlen ( raw ) );
|
|
53
|
+ size_t raw_bit_len = ( 8 * len );
|
53
|
54
|
unsigned int bit;
|
54
|
55
|
unsigned int tmp;
|
55
|
56
|
|
|
@@ -63,6 +64,7 @@ void base64_encode ( const char *raw, char *encoded ) {
|
63
|
64
|
*(encoded_bytes++) = '=';
|
64
|
65
|
*(encoded_bytes++) = '\0';
|
65
|
66
|
|
66
|
|
- DBG ( "Base64-encoded \"%s\" as \"%s\"\n", raw, encoded );
|
67
|
|
- assert ( strlen ( encoded ) == base64_encoded_len ( strlen ( raw ) ) );
|
|
67
|
+ DBG ( "Base64-encoded to \"%s\":\n", encoded );
|
|
68
|
+ DBG_HDA ( 0, raw, len );
|
|
69
|
+ assert ( strlen ( encoded ) == base64_encoded_len ( len ) );
|
68
|
70
|
}
|