14#ifndef DER_ENCODE_ENABLE
15#error Please define DER_ENCODE_ENABLE.
44 DERSize outLen = DERLengthOfTag(tag);
48 if(outLen > *inOutLen) {
54 *buf = (
DERByte)(tag1 | tagNumber);
58 DERByte *tagBytes = buf + outLen;
60 *--tagBytes = tagNumber & 0x7F;
62 while(tagNumber != 0) {
63 *--tagBytes = (tagNumber & 0x7F) | 0x80;
100 if(outLen > *inOutLen) {
112 *buf = (
DERByte)((outLen - 1) | 0x80);
113 lenBytes = buf + outLen - 1;
140 if(bytesLeft > *inOutLen) {
143 *inOutLen = bytesLeft;
147 drtn = DEREncodeTag(tag, currPtr, &itemLen);
152 bytesLeft -= itemLen;
159 bytesLeft -= itemLen;
166DERSize DERContentLengthOfEncodedSequence(
177 for(dex=0; dex<numItems; dex++) {
185 contentLen += itemSrc->
length;
202 contentLen += DERLengthOfTag(currItemSpec->tag);
205 thisContentLen = itemSrc->
length;
208 if(itemSrc->
data[0] & 0x80) {
214 contentLen += thisContentLen;
228 const DERByte *endPtr = derOut + *inOutLen;
238 drtn = DEREncodeTag(topTag, currPtr, &itemLen);
243 bytesLeft -= itemLen;
244 if(currPtr >= endPtr) {
249 contentLen = DERContentLengthOfEncodedSequence(src, numItems, itemSpecs);
256 bytesLeft -= itemLen;
257 if(currPtr + contentLen > endPtr) {
263 for(dex=0; dex<numItems; dex++) {
273 currPtr += itemSrc->
length;
274 bytesLeft -= itemSrc->
length;
285 drtn = DEREncodeTag(currItemSpec->tag, currPtr, &itemLen);
290 bytesLeft -= itemLen;
293 contentLen = itemSrc->
length;
296 if(itemSrc->
data[0] & 0x80) {
310 bytesLeft -= itemLen;
318 currPtr += itemSrc->
length;
319 bytesLeft -= itemSrc->
length;
321 *inOutLen = (currPtr - derOut);
333 DERSize contentLen = DERContentLengthOfEncodedSequence(
334 src, numItems, itemSpecs);
336 return DERLengthOfTag(topTag) +
DERReturn DEREncodeSequence(DERTag topTag, const void *src, DERShort numItems, const DERItemSpec *itemSpecs, DERByte *derOut, DERSize *inOutLen)
DERReturn DEREncodeLength(DERSize length, DERByte *buf, DERSize *inOutLen)
DERSize DERLengthOfEncodedSequence(DERTag topTag, const void *src, DERShort numItems, const DERItemSpec *itemSpecs)
DERReturn DEREncodeItem(DERTag tag, DERSize length, const DERByte *src, DERByte *derOut, DERSize *inOutLen)
#define DER_ENC_WRITE_DER
DERSize DERLengthOfItem(DERTag tag, DERSize length)
#define DER_ENC_SIGNED_INT
DERSize DERLengthOfLength(DERSize length)
#define DERMemmove(dst, src, len)