security/nss/lib/util/secder.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 #ifndef _SECDER_H_
michael@0 6 #define _SECDER_H_
michael@0 7
michael@0 8 #include "utilrename.h"
michael@0 9
michael@0 10 /*
michael@0 11 * secder.h - public data structures and prototypes for the DER encoding and
michael@0 12 * decoding utilities library
michael@0 13 */
michael@0 14
michael@0 15 #include <time.h>
michael@0 16
michael@0 17 #include "plarena.h"
michael@0 18 #include "prlong.h"
michael@0 19
michael@0 20 #include "seccomon.h"
michael@0 21 #include "secdert.h"
michael@0 22 #include "prtime.h"
michael@0 23
michael@0 24 SEC_BEGIN_PROTOS
michael@0 25
michael@0 26 /*
michael@0 27 ** Encode a data structure into DER.
michael@0 28 ** "dest" will be filled in (and memory allocated) to hold the der
michael@0 29 ** encoded structure in "src"
michael@0 30 ** "t" is a template structure which defines the shape of the
michael@0 31 ** stored data
michael@0 32 ** "src" is a pointer to the structure that will be encoded
michael@0 33 */
michael@0 34 extern SECStatus DER_Encode(PLArenaPool *arena, SECItem *dest, DERTemplate *t,
michael@0 35 void *src);
michael@0 36
michael@0 37 extern SECStatus DER_Lengths(SECItem *item, int *header_len_p,
michael@0 38 PRUint32 *contents_len_p);
michael@0 39
michael@0 40 /*
michael@0 41 ** Lower level der subroutine that stores the standard header into "to".
michael@0 42 ** The header is of variable length, based on encodingLen.
michael@0 43 ** The return value is the new value of "to" after skipping over the header.
michael@0 44 ** "to" is where the header will be stored
michael@0 45 ** "code" is the der code to write
michael@0 46 ** "encodingLen" is the number of bytes of data that will follow
michael@0 47 ** the header
michael@0 48 */
michael@0 49 extern unsigned char *DER_StoreHeader(unsigned char *to, unsigned int code,
michael@0 50 PRUint32 encodingLen);
michael@0 51
michael@0 52 /*
michael@0 53 ** Return the number of bytes it will take to hold a der encoded length.
michael@0 54 */
michael@0 55 extern int DER_LengthLength(PRUint32 len);
michael@0 56
michael@0 57 /*
michael@0 58 ** Store a der encoded *signed* integer (whose value is "src") into "dst".
michael@0 59 ** XXX This should really be enhanced to take a long.
michael@0 60 */
michael@0 61 extern SECStatus DER_SetInteger(PLArenaPool *arena, SECItem *dst, PRInt32 src);
michael@0 62
michael@0 63 /*
michael@0 64 ** Store a der encoded *unsigned* integer (whose value is "src") into "dst".
michael@0 65 ** XXX This should really be enhanced to take an unsigned long.
michael@0 66 */
michael@0 67 extern SECStatus DER_SetUInteger(PLArenaPool *arena, SECItem *dst, PRUint32 src);
michael@0 68
michael@0 69 /*
michael@0 70 ** Decode a der encoded *signed* integer that is stored in "src".
michael@0 71 ** If "-1" is returned, then the caller should check the error in
michael@0 72 ** XP_GetError() to see if an overflow occurred (SEC_ERROR_BAD_DER).
michael@0 73 */
michael@0 74 extern long DER_GetInteger(const SECItem *src);
michael@0 75
michael@0 76 /*
michael@0 77 ** Decode a der encoded *unsigned* integer that is stored in "src".
michael@0 78 ** If the ULONG_MAX is returned, then the caller should check the error
michael@0 79 ** in XP_GetError() to see if an overflow occurred (SEC_ERROR_BAD_DER).
michael@0 80 */
michael@0 81 extern unsigned long DER_GetUInteger(SECItem *src);
michael@0 82
michael@0 83 /*
michael@0 84 ** Convert an NSPR time value to a der encoded time value.
michael@0 85 ** "result" is the der encoded time (memory is allocated)
michael@0 86 ** "time" is the NSPR time value (Since Jan 1st, 1970).
michael@0 87 ** time must be on or after January 1, 1950, and
michael@0 88 ** before January 1, 2050
michael@0 89 ** The caller is responsible for freeing up the buffer which
michael@0 90 ** result->data points to upon a successful operation.
michael@0 91 */
michael@0 92 extern SECStatus DER_TimeToUTCTime(SECItem *result, PRTime time);
michael@0 93 extern SECStatus DER_TimeToUTCTimeArena(PLArenaPool* arenaOpt,
michael@0 94 SECItem *dst, PRTime gmttime);
michael@0 95
michael@0 96
michael@0 97 /*
michael@0 98 ** Convert an ascii encoded time value (according to DER rules) into
michael@0 99 ** an NSPR time value.
michael@0 100 ** "result" the resulting NSPR time
michael@0 101 ** "string" the der notation ascii value to decode
michael@0 102 */
michael@0 103 extern SECStatus DER_AsciiToTime(PRTime *result, const char *string);
michael@0 104
michael@0 105 /*
michael@0 106 ** Same as DER_AsciiToTime except takes an SECItem instead of a string
michael@0 107 */
michael@0 108 extern SECStatus DER_UTCTimeToTime(PRTime *result, const SECItem *time);
michael@0 109
michael@0 110 /*
michael@0 111 ** Convert a DER encoded UTC time to an ascii time representation
michael@0 112 ** "utctime" is the DER encoded UTC time to be converted. The
michael@0 113 ** caller is responsible for deallocating the returned buffer.
michael@0 114 */
michael@0 115 extern char *DER_UTCTimeToAscii(SECItem *utcTime);
michael@0 116
michael@0 117 /*
michael@0 118 ** Convert a DER encoded UTC time to an ascii time representation, but only
michael@0 119 ** include the day, not the time.
michael@0 120 ** "utctime" is the DER encoded UTC time to be converted.
michael@0 121 ** The caller is responsible for deallocating the returned buffer.
michael@0 122 */
michael@0 123 extern char *DER_UTCDayToAscii(SECItem *utctime);
michael@0 124 /* same thing for DER encoded GeneralizedTime */
michael@0 125 extern char *DER_GeneralizedDayToAscii(SECItem *gentime);
michael@0 126 /* same thing for either DER UTCTime or GeneralizedTime */
michael@0 127 extern char *DER_TimeChoiceDayToAscii(SECItem *timechoice);
michael@0 128
michael@0 129 /*
michael@0 130 ** Convert a PRTime to a DER encoded Generalized time
michael@0 131 ** gmttime must be on or after January 1, year 1 and
michael@0 132 ** before January 1, 10000.
michael@0 133 */
michael@0 134 extern SECStatus DER_TimeToGeneralizedTime(SECItem *dst, PRTime gmttime);
michael@0 135 extern SECStatus DER_TimeToGeneralizedTimeArena(PLArenaPool* arenaOpt,
michael@0 136 SECItem *dst, PRTime gmttime);
michael@0 137
michael@0 138 /*
michael@0 139 ** Convert a DER encoded Generalized time value into an NSPR time value.
michael@0 140 ** "dst" the resulting NSPR time
michael@0 141 ** "string" the der notation ascii value to decode
michael@0 142 */
michael@0 143 extern SECStatus DER_GeneralizedTimeToTime(PRTime *dst, const SECItem *time);
michael@0 144
michael@0 145 /*
michael@0 146 ** Convert from a PRTime UTC time value to a formatted ascii value. The
michael@0 147 ** caller is responsible for deallocating the returned buffer.
michael@0 148 */
michael@0 149 extern char *CERT_UTCTime2FormattedAscii (PRTime utcTime, char *format);
michael@0 150 #define CERT_GeneralizedTime2FormattedAscii CERT_UTCTime2FormattedAscii
michael@0 151
michael@0 152 /*
michael@0 153 ** Convert from a PRTime Generalized time value to a formatted ascii value. The
michael@0 154 ** caller is responsible for deallocating the returned buffer.
michael@0 155 */
michael@0 156 extern char *CERT_GenTime2FormattedAscii (PRTime genTime, char *format);
michael@0 157
michael@0 158 /*
michael@0 159 ** decode a SECItem containing either a SEC_ASN1_GENERALIZED_TIME
michael@0 160 ** or a SEC_ASN1_UTC_TIME
michael@0 161 */
michael@0 162
michael@0 163 extern SECStatus DER_DecodeTimeChoice(PRTime* output, const SECItem* input);
michael@0 164
michael@0 165 /* encode a PRTime to an ASN.1 DER SECItem containing either a
michael@0 166 SEC_ASN1_GENERALIZED_TIME or a SEC_ASN1_UTC_TIME */
michael@0 167
michael@0 168 extern SECStatus DER_EncodeTimeChoice(PLArenaPool* arena, SECItem* output,
michael@0 169 PRTime input);
michael@0 170
michael@0 171 SEC_END_PROTOS
michael@0 172
michael@0 173 #endif /* _SECDER_H_ */
michael@0 174

mercurial