MCPcopy Create free account
hub / github.com/apple/foundationdb / decode

Function decode

fdbrpc/Base64UrlDecode.cpp:55–99  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

53}
54
55int decode(const uint8_t* __restrict codeIn, const int lengthIn, uint8_t* __restrict plaintextOut) noexcept {
56 const uint8_t* codechar = codeIn;
57 const uint8_t* const codeEnd = codeIn + lengthIn;
58 uint8_t* plainchar = plaintextOut;
59 uint8_t fragment = 0;
60
61 while (1) {
62 // code 1 of 4
63 if (codechar == codeEnd) {
64 return plainchar - plaintextOut;
65 }
66 fragment = decodeValue(*codechar++);
67 if (fragment == _X)
68 return -1;
69 *plainchar = (fragment & 0x03f) << 2;
70 if (codechar == codeEnd) {
71 return -1; // requires at least 2 chars to decode 1 plain byte
72 }
73 // code 2 of 4
74 fragment = decodeValue(*codechar++);
75 if (fragment == _X)
76 return -1;
77 *plainchar++ |= (fragment & 0x030) >> 4;
78 if (codechar == codeEnd) {
79 return plainchar - plaintextOut;
80 }
81 *plainchar = (fragment & 0x00f) << 4;
82 // code 3 of 4
83 fragment = decodeValue(*codechar++);
84 if (fragment == _X)
85 return -1;
86 *plainchar++ |= (fragment >> 2);
87 if (codechar == codeEnd) {
88 return plainchar - plaintextOut;
89 }
90 *plainchar = (fragment & 0x003) << 6;
91 // code 4 of 4
92 fragment = decodeValue(*codechar++);
93 if (fragment == _X)
94 return -1;
95 *plainchar++ |= (fragment & 0x03f);
96 }
97 /* control should not reach here */
98 return plainchar - plaintextOut;
99}
100
101int decodedLength(int codeLength) noexcept {
102 const auto r = (codeLength & 3);

Callers 15

for_each_codepointFunction · 0.85
decodeMethod · 0.85
insertTenantMethod · 0.85
_setupMethod · 0.85
_setupMethod · 0.85
decodeMethod · 0.85
unpackMethod · 0.85

Calls 5

decodedLengthFunction · 0.85
decodeValueFunction · 0.70
StringRefClass · 0.50
sizeMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected