| 36 | } |
| 37 | |
| 38 | bool BERLengthDecode(BufferedTransformation &bt, lword &length, bool &definiteLength) |
| 39 | { |
| 40 | byte b; |
| 41 | |
| 42 | if (!bt.Get(b)) |
| 43 | return false; |
| 44 | |
| 45 | if (!(b & 0x80)) |
| 46 | { |
| 47 | definiteLength = true; |
| 48 | length = b; |
| 49 | } |
| 50 | else |
| 51 | { |
| 52 | unsigned int lengthBytes = b & 0x7f; |
| 53 | |
| 54 | if (lengthBytes == 0) |
| 55 | { |
| 56 | definiteLength = false; |
| 57 | return true; |
| 58 | } |
| 59 | |
| 60 | definiteLength = true; |
| 61 | length = 0; |
| 62 | while (lengthBytes--) |
| 63 | { |
| 64 | if (length >> (8*(sizeof(length)-1))) |
| 65 | BERDecodeError(); // length about to overflow |
| 66 | |
| 67 | if (!bt.Get(b)) |
| 68 | return false; |
| 69 | |
| 70 | length = (length << 8) | b; |
| 71 | } |
| 72 | } |
| 73 | return true; |
| 74 | } |
| 75 | |
| 76 | bool BERLengthDecode(BufferedTransformation &bt, size_t &length) |
| 77 | { |
no test coverage detected