put sequence encoded dsa signature into decoded in 2 20 byte integers
| 1193 | |
| 1194 | // put sequence encoded dsa signature into decoded in 2 20 byte integers |
| 1195 | word32 DecodeDSA_Signature(byte* decoded, const byte* encoded, word32 sz) |
| 1196 | { |
| 1197 | Source source(encoded, sz); |
| 1198 | |
| 1199 | if (source.next() != (SEQUENCE | CONSTRUCTED)) { |
| 1200 | source.SetError(SEQUENCE_E); |
| 1201 | return 0; |
| 1202 | } |
| 1203 | |
| 1204 | GetLength(source); // total |
| 1205 | |
| 1206 | // r |
| 1207 | if (source.next() != INTEGER) { |
| 1208 | source.SetError(INTEGER_E); |
| 1209 | return 0; |
| 1210 | } |
| 1211 | word32 rLen = GetLength(source); |
| 1212 | if (rLen != 20) { |
| 1213 | if (rLen == 21) { // zero at front, eat |
| 1214 | source.next(); |
| 1215 | --rLen; |
| 1216 | } |
| 1217 | else if (rLen == 19) { // add zero to front so 20 bytes |
| 1218 | decoded[0] = 0; |
| 1219 | decoded++; |
| 1220 | } |
| 1221 | else { |
| 1222 | source.SetError(DSA_SZ_E); |
| 1223 | return 0; |
| 1224 | } |
| 1225 | } |
| 1226 | memcpy(decoded, source.get_buffer() + source.get_index(), rLen); |
| 1227 | source.advance(rLen); |
| 1228 | |
| 1229 | // s |
| 1230 | if (source.next() != INTEGER) { |
| 1231 | source.SetError(INTEGER_E); |
| 1232 | return 0; |
| 1233 | } |
| 1234 | word32 sLen = GetLength(source); |
| 1235 | if (sLen != 20) { |
| 1236 | if (sLen == 21) { |
| 1237 | source.next(); // zero at front, eat |
| 1238 | --sLen; |
| 1239 | } |
| 1240 | else if (sLen == 19) { |
| 1241 | decoded[rLen] = 0; // add zero to front so 20 bytes |
| 1242 | decoded++; |
| 1243 | } |
| 1244 | else { |
| 1245 | source.SetError(DSA_SZ_E); |
| 1246 | return 0; |
| 1247 | } |
| 1248 | } |
| 1249 | memcpy(decoded + rLen, source.get_buffer() + source.get_index(), sLen); |
| 1250 | source.advance(sLen); |
| 1251 | |
| 1252 | return 40; |