Own fork of MbedSmartRest
Dependents: MbedSmartRestMain MbedSmartRestMain
Fork of MbedSmartRest by
Diff: b64.cpp
- Revision:
- 20:505d29d5bdfc
- Parent:
- 0:099f76422485
- Child:
- 22:832cb27c28f9
diff -r 81dfc04ce0bb -r 505d29d5bdfc b64.cpp --- a/b64.cpp Fri Mar 20 14:26:52 2015 +0000 +++ b/b64.cpp Mon Apr 13 14:24:44 2015 +0000 @@ -22,8 +22,7 @@ { // Work out if we've got enough space to encode the input // Every 6 bits of input becomes a byte of output - if (aOutputLen < (aInputLen*8)/6) - { + if (aOutputLen < (aInputLen*8)/6) { // FIXME Should we return an error here, or just the length return (aInputLen*8)/6; } @@ -37,31 +36,23 @@ aOutput[1] = b64_dictionary[(aInput[0] & 0x3)<<4|(aInput[1]>>4)]; aOutput[2] = b64_dictionary[(aInput[1]&0x0F)<<2|(aInput[2]>>6)]; aOutput[3] = b64_dictionary[aInput[2]&0x3F]; - } - else if (aInputLen == 2) - { + } else if (aInputLen == 2) { aOutput[0] = b64_dictionary[aInput[0] >> 2]; aOutput[1] = b64_dictionary[(aInput[0] & 0x3)<<4|(aInput[1]>>4)]; aOutput[2] = b64_dictionary[(aInput[1]&0x0F)<<2]; aOutput[3] = '='; - } - else if (aInputLen == 1) - { + } else if (aInputLen == 1) { aOutput[0] = b64_dictionary[aInput[0] >> 2]; aOutput[1] = b64_dictionary[(aInput[0] & 0x3)<<4]; aOutput[2] = '='; aOutput[3] = '='; - } - else - { + } else { // Break the input into 3-byte chunks and process each of them int i; - for (i = 0; i < aInputLen/3; i++) - { + for (i = 0; i < aInputLen/3; i++) { b64_encode(&aInput[i*3], 3, &aOutput[i*4], 4); } - if (aInputLen % 3 > 0) - { + if (aInputLen % 3 > 0) { // It doesn't fit neatly into a 3-byte chunk, so process what's left b64_encode(&aInput[i*3], aInputLen % 3, &aOutput[i*4], aOutputLen - (i*4)); }