tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

secoid.h (6109B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 #ifndef _SECOID_H_
      6 #define _SECOID_H_
      7 
      8 #include "utilrename.h"
      9 
     10 /*
     11 * secoid.h - public data structures and prototypes for ASN.1 OID functions
     12 */
     13 
     14 #include "plarena.h"
     15 
     16 #include "seccomon.h"
     17 #include "secoidt.h"
     18 #include "secasn1t.h"
     19 
     20 SEC_BEGIN_PROTOS
     21 
     22 extern const SEC_ASN1Template SECOID_AlgorithmIDTemplate[];
     23 
     24 /* This functions simply returns the address of the above-declared template. */
     25 SEC_ASN1_CHOOSER_DECLARE(SECOID_AlgorithmIDTemplate)
     26 
     27 /*
     28 * OID handling routines
     29 */
     30 extern SECOidData *SECOID_FindOID(const SECItem *oid);
     31 extern SECOidTag SECOID_FindOIDTag(const SECItem *oid);
     32 extern SECOidData *SECOID_FindOIDByTag(SECOidTag tagnum);
     33 extern SECOidData *SECOID_FindOIDByMechanism(unsigned long mechanism);
     34 extern SECOidTag SECOID_FindOIDTagFromDescripton(const char *string,
     35                                                 size_t len,
     36                                                 PRBool isCipher);
     37 
     38 /****************************************/
     39 /*
     40 ** Algorithm id handling operations
     41 */
     42 
     43 /*
     44 ** Fill in an algorithm-ID object given a tag and some parameters.
     45 **      "aid" where the DER encoded algorithm info is stored (memory
     46 **         is allocated)
     47 **      "tag" the tag number defining the algorithm
     48 **      "params" if not NULL, the parameters to go with the algorithm
     49 */
     50 extern SECStatus SECOID_SetAlgorithmID(PLArenaPool *arena, SECAlgorithmID *aid,
     51                                       SECOidTag tag, SECItem *params);
     52 
     53 /*
     54 ** Copy the "src" object to "dest". Memory is allocated in "dest" for
     55 ** each of the appropriate sub-objects. Memory in "dest" is not freed
     56 ** before memory is allocated (use SECOID_DestroyAlgorithmID(dest, PR_FALSE)
     57 ** to do that).
     58 */
     59 extern SECStatus SECOID_CopyAlgorithmID(PLArenaPool *arena, SECAlgorithmID *dest,
     60                                        const SECAlgorithmID *src);
     61 
     62 /*
     63 ** Get the tag number for the given algorithm-id object.
     64 */
     65 extern SECOidTag SECOID_GetAlgorithmTag(const SECAlgorithmID *aid);
     66 
     67 /*
     68 ** Get the number of valid tags in the current system. This includes dynamic
     69 ** tags. This value can grow but never shrink. This is more reliable than using
     70 ** SEC_OID_TOTAL because 1) it includes dynamic tags, and 2) it includes any
     71 ** new tags the nss library has added since the last time the application
     72 ** was compilied.
     73 */
     74 extern SECOidTag SECOID_GetTotalTags(void);
     75 
     76 /*
     77 ** Destroy an algorithm-id object.
     78 **      "aid" the certificate-request to destroy
     79 **      "freeit" if PR_TRUE then free the object as well as its sub-objects
     80 */
     81 extern void SECOID_DestroyAlgorithmID(SECAlgorithmID *aid, PRBool freeit);
     82 
     83 /*
     84 ** Compare two algorithm-id objects, returning the difference between
     85 ** them.
     86 */
     87 extern SECComparison SECOID_CompareAlgorithmID(SECAlgorithmID *a,
     88                                               SECAlgorithmID *b);
     89 
     90 extern PRBool SECOID_KnownCertExtenOID(SECItem *extenOid);
     91 
     92 /* Given a tag number, return a string describing it.
     93 */
     94 extern const char *SECOID_FindOIDTagDescription(SECOidTag tagnum);
     95 
     96 /* Add a dynamic SECOidData to the dynamic OID table.
     97 ** Routine copies the src entry, and returns the new SECOidTag.
     98 ** Returns SEC_OID_INVALID if failed to add for some reason.
     99 */
    100 extern SECOidTag SECOID_AddEntry(const SECOidData *src);
    101 
    102 /*
    103 * initialize the oid data structures.
    104 */
    105 extern SECStatus SECOID_Init(void);
    106 
    107 /*
    108 * free up the oid data structures.
    109 */
    110 extern SECStatus SECOID_Shutdown(void);
    111 
    112 /* if to->data is not NULL, and to->len is large enough to hold the result,
    113 * then the resultant OID will be copyed into to->data, and to->len will be
    114 * changed to show the actual OID length.
    115 * Otherwise, memory for the OID will be allocated (from the caller's
    116 * PLArenaPool, if pool is non-NULL) and to->data will receive the address
    117 * of the allocated data, and to->len will receive the OID length.
    118 * The original value of to->data is not freed when a new buffer is allocated.
    119 *
    120 * The input string may begin with "OID." and this still be ignored.
    121 * The length of the input string is given in len.  If len == 0, then
    122 * len will be computed as strlen(from), meaning it must be NUL terminated.
    123 * It is an error if from == NULL, or if *from == '\0'.
    124 */
    125 extern SECStatus SEC_StringToOID(PLArenaPool *pool, SECItem *to,
    126                                 const char *from, PRUint32 len);
    127 
    128 extern void UTIL_SetForkState(PRBool forked);
    129 
    130 /*
    131 * Accessor functions for new opaque extended SECOID table.
    132 * Any of these functions may return SECSuccess or SECFailure with the error
    133 * code set to SEC_ERROR_UNKNOWN_OBJECT_TYPE if the SECOidTag is out of range.
    134 */
    135 
    136 /* The Get function outputs the 32-bit value associated with the SECOidTag.
    137 * Flags bits are the NSS_USE_ALG_ #defines in "secoidt.h".
    138 * Default value for any algorithm is 0xffffffff (enabled for all purposes).
    139 * No value is output if function returns SECFailure.
    140 */
    141 extern SECStatus NSS_GetAlgorithmPolicy(SECOidTag tag, PRUint32 *pValue);
    142 
    143 /* The Set function modifies the stored value according to the following
    144 * algorithm:
    145 *   policy[tag] = (policy[tag] & ~clearBits) | setBits;
    146 */
    147 extern SECStatus
    148 NSS_SetAlgorithmPolicy(SECOidTag tag, PRUint32 setBits, PRUint32 clearBits);
    149 
    150 /* Set all the tags to a particular policy (like to clear all S/MIME bits */
    151 extern SECStatus
    152 NSS_SetAlgorithmPolicyAll(PRUint32 setBits, PRUint32 clearBits);
    153 
    154 /* Get all the tags with a particular policy. The policy must match the exact
    155 * value after applying the mask. Caller is responsible for
    156 * freeing the tag array with PORT_Free() */
    157 extern SECStatus
    158 NSS_GetAlgorithmPolicyAll(PRUint32 maskBits, PRUint32 valueBits,
    159                          SECOidTag **outTags, int *outTagCount);
    160 
    161 /* Lock the policy so NSS_SetAlgorithmPolicy (and other policy functions)
    162 * No longer function */
    163 void
    164 NSS_LockPolicy(void);
    165 
    166 /* return true if policy changes are now locked out */
    167 PRBool
    168 NSS_IsPolicyLocked(void);
    169 
    170 SEC_END_PROTOS
    171 
    172 #endif /* _SECOID_H_ */