=========================== ===========================
| 120 | // |
| 121 | // =========================== |
| 122 | int encodeB64(int n, unsigned char *inBytes, unsigned char *outBytes) { |
| 123 | if (inBytes == NULL || outBytes == NULL || n <= 0) { |
| 124 | return 0; |
| 125 | } |
| 126 | |
| 127 | int m = n - (n % 3); |
| 128 | int ii, jj; |
| 129 | jj = 0; |
| 130 | |
| 131 | for (ii = 0; ii < m; ii += 3) { |
| 132 | encodeB64_3Bytes(inBytes + ii, outBytes + jj); |
| 133 | jj = jj + 4; |
| 134 | } |
| 135 | |
| 136 | if (m != n) { |
| 137 | unsigned char lastBytes[3] = {0, 0, 0}; |
| 138 | // give last (n-m) chars |
| 139 | lastBytes[0] = inBytes[ii]; |
| 140 | if ((n - m) == 2) { |
| 141 | lastBytes[1] = inBytes[ii + 1]; |
| 142 | } |
| 143 | |
| 144 | // encoding chars |
| 145 | encodeB64_3Bytes(lastBytes, outBytes + jj); |
| 146 | // definition of bytes which is not encoding |
| 147 | outBytes[jj + 3] = '='; |
| 148 | if ((n - m) == 1) { |
| 149 | outBytes[jj + 2] = '='; |
| 150 | } |
| 151 | |
| 152 | jj = jj + 4; |
| 153 | } |
| 154 | |
| 155 | return jj; |
| 156 | } |
| 157 | |
| 158 | int runEncodeB64(int n, unsigned char *inBytes, unsigned char *outBytes) { |
| 159 | static int nbcached = 0; |
no test coverage detected