secoid.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. #ifndef _SECOID_H_
  5. #define _SECOID_H_
  6. #include "utilrename.h"
  7. /*
  8. * secoid.h - public data structures and prototypes for ASN.1 OID functions
  9. */
  10. #include "plarena.h"
  11. #include "seccomon.h"
  12. #include "secoidt.h"
  13. #include "secasn1t.h"
  14. SEC_BEGIN_PROTOS
  15. extern const SEC_ASN1Template SECOID_AlgorithmIDTemplate[];
  16. /* This functions simply returns the address of the above-declared template. */
  17. SEC_ASN1_CHOOSER_DECLARE(SECOID_AlgorithmIDTemplate)
  18. /*
  19. * OID handling routines
  20. */
  21. extern SECOidData *SECOID_FindOID(const SECItem *oid);
  22. extern SECOidTag SECOID_FindOIDTag(const SECItem *oid);
  23. extern SECOidData *SECOID_FindOIDByTag(SECOidTag tagnum);
  24. extern SECOidData *SECOID_FindOIDByMechanism(unsigned long mechanism);
  25. /****************************************/
  26. /*
  27. ** Algorithm id handling operations
  28. */
  29. /*
  30. ** Fill in an algorithm-ID object given a tag and some parameters.
  31. ** "aid" where the DER encoded algorithm info is stored (memory
  32. ** is allocated)
  33. ** "tag" the tag number defining the algorithm
  34. ** "params" if not NULL, the parameters to go with the algorithm
  35. */
  36. extern SECStatus SECOID_SetAlgorithmID(PLArenaPool *arena, SECAlgorithmID *aid,
  37. SECOidTag tag, SECItem *params);
  38. /*
  39. ** Copy the "src" object to "dest". Memory is allocated in "dest" for
  40. ** each of the appropriate sub-objects. Memory in "dest" is not freed
  41. ** before memory is allocated (use SECOID_DestroyAlgorithmID(dest, PR_FALSE)
  42. ** to do that).
  43. */
  44. extern SECStatus SECOID_CopyAlgorithmID(PLArenaPool *arena, SECAlgorithmID *dest,
  45. const SECAlgorithmID *src);
  46. /*
  47. ** Get the tag number for the given algorithm-id object.
  48. */
  49. extern SECOidTag SECOID_GetAlgorithmTag(const SECAlgorithmID *aid);
  50. /*
  51. ** Destroy an algorithm-id object.
  52. ** "aid" the certificate-request to destroy
  53. ** "freeit" if PR_TRUE then free the object as well as its sub-objects
  54. */
  55. extern void SECOID_DestroyAlgorithmID(SECAlgorithmID *aid, PRBool freeit);
  56. /*
  57. ** Compare two algorithm-id objects, returning the difference between
  58. ** them.
  59. */
  60. extern SECComparison SECOID_CompareAlgorithmID(SECAlgorithmID *a,
  61. SECAlgorithmID *b);
  62. extern PRBool SECOID_KnownCertExtenOID(SECItem *extenOid);
  63. /* Given a tag number, return a string describing it.
  64. */
  65. extern const char *SECOID_FindOIDTagDescription(SECOidTag tagnum);
  66. /* Add a dynamic SECOidData to the dynamic OID table.
  67. ** Routine copies the src entry, and returns the new SECOidTag.
  68. ** Returns SEC_OID_INVALID if failed to add for some reason.
  69. */
  70. extern SECOidTag SECOID_AddEntry(const SECOidData *src);
  71. /*
  72. * initialize the oid data structures.
  73. */
  74. extern SECStatus SECOID_Init(void);
  75. /*
  76. * free up the oid data structures.
  77. */
  78. extern SECStatus SECOID_Shutdown(void);
  79. /* if to->data is not NULL, and to->len is large enough to hold the result,
  80. * then the resultant OID will be copyed into to->data, and to->len will be
  81. * changed to show the actual OID length.
  82. * Otherwise, memory for the OID will be allocated (from the caller's
  83. * PLArenaPool, if pool is non-NULL) and to->data will receive the address
  84. * of the allocated data, and to->len will receive the OID length.
  85. * The original value of to->data is not freed when a new buffer is allocated.
  86. *
  87. * The input string may begin with "OID." and this still be ignored.
  88. * The length of the input string is given in len. If len == 0, then
  89. * len will be computed as strlen(from), meaning it must be NUL terminated.
  90. * It is an error if from == NULL, or if *from == '\0'.
  91. */
  92. extern SECStatus SEC_StringToOID(PLArenaPool *pool, SECItem *to,
  93. const char *from, PRUint32 len);
  94. extern void UTIL_SetForkState(PRBool forked);
  95. /*
  96. * Accessor functions for new opaque extended SECOID table.
  97. * Any of these functions may return SECSuccess or SECFailure with the error
  98. * code set to SEC_ERROR_UNKNOWN_OBJECT_TYPE if the SECOidTag is out of range.
  99. */
  100. /* The Get function outputs the 32-bit value associated with the SECOidTag.
  101. * Flags bits are the NSS_USE_ALG_ #defines in "secoidt.h".
  102. * Default value for any algorithm is 0xffffffff (enabled for all purposes).
  103. * No value is output if function returns SECFailure.
  104. */
  105. extern SECStatus NSS_GetAlgorithmPolicy(SECOidTag tag, PRUint32 *pValue);
  106. /* The Set function modifies the stored value according to the following
  107. * algorithm:
  108. * policy[tag] = (policy[tag] & ~clearBits) | setBits;
  109. */
  110. extern SECStatus
  111. NSS_SetAlgorithmPolicy(SECOidTag tag, PRUint32 setBits, PRUint32 clearBits);
  112. SEC_END_PROTOS
  113. #endif /* _SECOID_H_ */