aboutsummaryrefslogtreecommitdiff
path: root/src/base64.cpp
diff options
context:
space:
mode:
authorMark Haines <mark.haines@matrix.org>2015-07-08 15:30:34 +0100
committerMark Haines <mark.haines@matrix.org>2015-07-08 15:30:34 +0100
commit532dc0d4e79192a0c7fd1758322f6cae06959859 (patch)
treed8c553a7601c2688e04c74aed36979478d9f9f71 /src/base64.cpp
parentdceae043b30efb672acf41b21fbb335a6710b3c1 (diff)
Change the JSON format for one time keys to include what algorithm they are for
Diffstat (limited to 'src/base64.cpp')
-rw-r--r--src/base64.cpp16
1 files changed, 7 insertions, 9 deletions
diff --git a/src/base64.cpp b/src/base64.cpp
index a8631a1..bf8492e 100644
--- a/src/base64.cpp
+++ b/src/base64.cpp
@@ -45,14 +45,7 @@ static const std::uint8_t DECODE_BASE64[128] = {
} // namespace
-std::size_t olm::encode_base64_length(
- std::size_t input_length
-) {
- return 4 * ((input_length + 2) / 3) + (input_length + 2) % 3 - 2;
-}
-
-
-void olm::encode_base64(
+std::uint8_t * olm::encode_base64(
std::uint8_t const * input, std::size_t input_length,
std::uint8_t * output
) {
@@ -70,6 +63,7 @@ void olm::encode_base64(
output += 4;
}
unsigned remainder = input + input_length - pos;
+ std::uint8_t * result = output;
if (remainder) {
unsigned value = pos[0];
if (remainder == 2) {
@@ -77,13 +71,16 @@ void olm::encode_base64(
value <<= 2;
output[2] = ENCODE_BASE64[value & 0x3F];
value >>= 6;
+ result += 3;
} else {
value <<= 4;
+ result += 2;
}
output[1] = ENCODE_BASE64[value & 0x3F];
value >>= 6;
output[0] = ENCODE_BASE64[value];
}
+ return result;
}
@@ -98,7 +95,7 @@ std::size_t olm::decode_base64_length(
}
-void olm::decode_base64(
+std::uint8_t const * olm::decode_base64(
std::uint8_t const * input, std::size_t input_length,
std::uint8_t * output
) {
@@ -129,4 +126,5 @@ void olm::decode_base64(
}
output[0] = value;
}
+ return input + input_length;
}