security/nss/lib/util/secder.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/security/nss/lib/util/secder.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,174 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +#ifndef _SECDER_H_
     1.9 +#define _SECDER_H_
    1.10 +
    1.11 +#include "utilrename.h"
    1.12 +
    1.13 +/*
    1.14 + * secder.h - public data structures and prototypes for the DER encoding and
    1.15 + *	      decoding utilities library
    1.16 + */
    1.17 +
    1.18 +#include <time.h>
    1.19 +
    1.20 +#include "plarena.h"
    1.21 +#include "prlong.h"
    1.22 +
    1.23 +#include "seccomon.h"
    1.24 +#include "secdert.h"
    1.25 +#include "prtime.h"
    1.26 +
    1.27 +SEC_BEGIN_PROTOS
    1.28 +
    1.29 +/*
    1.30 +** Encode a data structure into DER.
    1.31 +**	"dest" will be filled in (and memory allocated) to hold the der
    1.32 +**	   encoded structure in "src"
    1.33 +**	"t" is a template structure which defines the shape of the
    1.34 +**	   stored data
    1.35 +**	"src" is a pointer to the structure that will be encoded
    1.36 +*/
    1.37 +extern SECStatus DER_Encode(PLArenaPool *arena, SECItem *dest, DERTemplate *t,
    1.38 +			   void *src);
    1.39 +
    1.40 +extern SECStatus DER_Lengths(SECItem *item, int *header_len_p,
    1.41 +                             PRUint32 *contents_len_p);
    1.42 +
    1.43 +/*
    1.44 +** Lower level der subroutine that stores the standard header into "to".
    1.45 +** The header is of variable length, based on encodingLen.
    1.46 +** The return value is the new value of "to" after skipping over the header.
    1.47 +**	"to" is where the header will be stored
    1.48 +**	"code" is the der code to write
    1.49 +**	"encodingLen" is the number of bytes of data that will follow
    1.50 +**	   the header
    1.51 +*/
    1.52 +extern unsigned char *DER_StoreHeader(unsigned char *to, unsigned int code,
    1.53 +				      PRUint32 encodingLen);
    1.54 +
    1.55 +/*
    1.56 +** Return the number of bytes it will take to hold a der encoded length.
    1.57 +*/
    1.58 +extern int DER_LengthLength(PRUint32 len);
    1.59 +
    1.60 +/*
    1.61 +** Store a der encoded *signed* integer (whose value is "src") into "dst".
    1.62 +** XXX This should really be enhanced to take a long.
    1.63 +*/
    1.64 +extern SECStatus DER_SetInteger(PLArenaPool *arena, SECItem *dst, PRInt32 src);
    1.65 +
    1.66 +/*
    1.67 +** Store a der encoded *unsigned* integer (whose value is "src") into "dst".
    1.68 +** XXX This should really be enhanced to take an unsigned long.
    1.69 +*/
    1.70 +extern SECStatus DER_SetUInteger(PLArenaPool *arena, SECItem *dst, PRUint32 src);
    1.71 +
    1.72 +/*
    1.73 +** Decode a der encoded *signed* integer that is stored in "src".
    1.74 +** If "-1" is returned, then the caller should check the error in
    1.75 +** XP_GetError() to see if an overflow occurred (SEC_ERROR_BAD_DER).
    1.76 +*/
    1.77 +extern long DER_GetInteger(const SECItem *src);
    1.78 +
    1.79 +/*
    1.80 +** Decode a der encoded *unsigned* integer that is stored in "src".
    1.81 +** If the ULONG_MAX is returned, then the caller should check the error
    1.82 +** in XP_GetError() to see if an overflow occurred (SEC_ERROR_BAD_DER).
    1.83 +*/
    1.84 +extern unsigned long DER_GetUInteger(SECItem *src);
    1.85 +
    1.86 +/*
    1.87 +** Convert an NSPR time value to a der encoded time value.
    1.88 +**	"result" is the der encoded time (memory is allocated)
    1.89 +**	"time" is the NSPR time value (Since Jan 1st, 1970).
    1.90 +**      time must be on or after January 1, 1950, and
    1.91 +**      before January 1, 2050
    1.92 +** The caller is responsible for freeing up the buffer which
    1.93 +** result->data points to upon a successful operation.
    1.94 +*/
    1.95 +extern SECStatus DER_TimeToUTCTime(SECItem *result, PRTime time);
    1.96 +extern SECStatus DER_TimeToUTCTimeArena(PLArenaPool* arenaOpt,
    1.97 +                                        SECItem *dst, PRTime gmttime);
    1.98 +
    1.99 +
   1.100 +/*
   1.101 +** Convert an ascii encoded time value (according to DER rules) into
   1.102 +** an NSPR time value.
   1.103 +**	"result" the resulting NSPR time
   1.104 +**	"string" the der notation ascii value to decode
   1.105 +*/
   1.106 +extern SECStatus DER_AsciiToTime(PRTime *result, const char *string);
   1.107 +
   1.108 +/*
   1.109 +** Same as DER_AsciiToTime except takes an SECItem instead of a string
   1.110 +*/
   1.111 +extern SECStatus DER_UTCTimeToTime(PRTime *result, const SECItem *time);
   1.112 +
   1.113 +/*
   1.114 +** Convert a DER encoded UTC time to an ascii time representation
   1.115 +** "utctime" is the DER encoded UTC time to be converted. The
   1.116 +** caller is responsible for deallocating the returned buffer.
   1.117 +*/
   1.118 +extern char *DER_UTCTimeToAscii(SECItem *utcTime);
   1.119 +
   1.120 +/*
   1.121 +** Convert a DER encoded UTC time to an ascii time representation, but only
   1.122 +** include the day, not the time.
   1.123 +**	"utctime" is the DER encoded UTC time to be converted.
   1.124 +** The caller is responsible for deallocating the returned buffer.
   1.125 +*/
   1.126 +extern char *DER_UTCDayToAscii(SECItem *utctime);
   1.127 +/* same thing for DER encoded GeneralizedTime */
   1.128 +extern char *DER_GeneralizedDayToAscii(SECItem *gentime);
   1.129 +/* same thing for either DER UTCTime or GeneralizedTime */
   1.130 +extern char *DER_TimeChoiceDayToAscii(SECItem *timechoice);
   1.131 +
   1.132 +/*
   1.133 +** Convert a PRTime to a DER encoded Generalized time
   1.134 +** gmttime must be on or after January 1, year 1 and
   1.135 +** before January 1, 10000.
   1.136 +*/
   1.137 +extern SECStatus DER_TimeToGeneralizedTime(SECItem *dst, PRTime gmttime);
   1.138 +extern SECStatus DER_TimeToGeneralizedTimeArena(PLArenaPool* arenaOpt,
   1.139 +                                                SECItem *dst, PRTime gmttime);
   1.140 +
   1.141 +/*
   1.142 +** Convert a DER encoded Generalized time value into an NSPR time value.
   1.143 +**	"dst" the resulting NSPR time
   1.144 +**	"string" the der notation ascii value to decode
   1.145 +*/
   1.146 +extern SECStatus DER_GeneralizedTimeToTime(PRTime *dst, const SECItem *time);
   1.147 +
   1.148 +/*
   1.149 +** Convert from a PRTime UTC time value to a formatted ascii value. The
   1.150 +** caller is responsible for deallocating the returned buffer.
   1.151 +*/
   1.152 +extern char *CERT_UTCTime2FormattedAscii (PRTime utcTime, char *format);
   1.153 +#define CERT_GeneralizedTime2FormattedAscii CERT_UTCTime2FormattedAscii
   1.154 +
   1.155 +/*
   1.156 +** Convert from a PRTime Generalized time value to a formatted ascii value. The
   1.157 +** caller is responsible for deallocating the returned buffer.
   1.158 +*/
   1.159 +extern char *CERT_GenTime2FormattedAscii (PRTime genTime, char *format);
   1.160 +
   1.161 +/*
   1.162 +** decode a SECItem containing either a SEC_ASN1_GENERALIZED_TIME 
   1.163 +** or a SEC_ASN1_UTC_TIME
   1.164 +*/
   1.165 +
   1.166 +extern SECStatus DER_DecodeTimeChoice(PRTime* output, const SECItem* input);
   1.167 +
   1.168 +/* encode a PRTime to an ASN.1 DER SECItem containing either a
   1.169 +   SEC_ASN1_GENERALIZED_TIME or a SEC_ASN1_UTC_TIME */
   1.170 +
   1.171 +extern SECStatus DER_EncodeTimeChoice(PLArenaPool* arena, SECItem* output,
   1.172 +                                       PRTime input);
   1.173 +
   1.174 +SEC_END_PROTOS
   1.175 +
   1.176 +#endif /* _SECDER_H_ */
   1.177 +

mercurial