ObjId.h
上传用户:zbbssh
上传日期:2007-01-08
资源大小:196k
文件大小:6k
源码类别:

CA认证

开发平台:

C/C++

  1. /*
  2. ------------------------------------------------------------------
  3.   Copyright
  4.   Sun Microsystems, Inc.
  5.   Copyright (C) 1994, 1995, 1996 Sun Microsystems, Inc.  All Rights
  6.   Reserved.
  7.   Permission is hereby granted, free of charge, to any person
  8.   obtaining a copy of this software and associated documentation
  9.   files (the "Software"), to deal in the Software without
  10.   restriction, including without limitation the rights to use,
  11.   copy, modify, merge, publish, distribute, sublicense, and/or sell
  12.   copies of the Software or derivatives of the Software, and to 
  13.   permit persons to whom the Software or its derivatives is furnished 
  14.   to do so, subject to the following conditions:
  15.   The above copyright notice and this permission notice shall be
  16.   included in all copies or substantial portions of the Software.
  17.   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18.   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  19.   OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  20.   NONINFRINGEMENT.  IN NO EVENT SHALL SUN MICROSYSTEMS, INC., BE LIABLE
  21.   FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  22.   OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  23.   CONNECTION WITH THE SOFTWARE OR DERIVATES OF THIS SOFTWARE OR 
  24.   THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  25.   Except as contained in this notice, the name of Sun Microsystems, Inc.
  26.   shall not be used in advertising or otherwise to promote
  27.   the sale, use or other dealings in this Software or its derivatives 
  28.   without prior written authorization from Sun Microsystems, Inc.
  29. */
  30. #pragma ident "@(#)ObjId.h 1.9 96/01/29 Sun Microsystems"
  31. #ifndef OBJID_H
  32. #define OBJID_H
  33. /*
  34.  * Object ID class
  35.  */
  36. struct obj_id_elem {
  37. obj_id_elem *next;
  38. Bigint elemval;
  39. };
  40. class ObjId {
  41. obj_id_elem *obj_id_list;
  42.   public:
  43. // Constructors etc
  44. ObjId() {obj_id_list = NULL;};
  45. #ifndef __GNUC__
  46. ObjId(int , ...); // variable # of Bigints, 1st arg gives #
  47. #else
  48.        ObjId(int , Bigint=Bigint((short)0), Bigint=Bigint((short)0), 
  49.                    Bigint=Bigint((short)0), Bigint=Bigint((short)0), 
  50.                    Bigint=Bigint((short)0), Bigint=Bigint((short)0),
  51.                    Bigint=Bigint((short)0), Bigint=Bigint((short)0), 
  52.                    Bigint=Bigint((short)0), Bigint=Bigint((short)0), 
  53.                    Bigint=Bigint((short)0), Bigint=Bigint((short)0));
  54. #endif
  55. ~ObjId();
  56. ObjId(const ObjId &);
  57. // operators and member functions
  58. ObjId& operator =(const ObjId &);
  59. void add_element(const Bigint& );
  60. Bstream encode() const;
  61. friend Boolean operator ==(const ObjId&, const ObjId&);
  62. friend Boolean operator !=(const ObjId&, const ObjId&);
  63. void print() const;
  64. String getoidstr() const;
  65. };
  66. /*
  67.  * selected OIDs
  68.  */
  69. // From X.520
  70. const ObjId commonName (4, Bigint(2), Bigint(5), Bigint(4), Bigint(3));
  71. const ObjId surName (4, Bigint(2), Bigint(5), Bigint(4), Bigint(4));
  72. const ObjId countryName (4, Bigint(2), Bigint(5), Bigint(4), Bigint(6));
  73. const ObjId localityName(4, Bigint(2), Bigint(5), Bigint(4), Bigint(7));
  74. const ObjId stateName (4, Bigint(2), Bigint(5), Bigint(4), Bigint(8));
  75. const ObjId streetAddress(4, Bigint(2), Bigint(5), Bigint(4), Bigint(9));
  76. const ObjId orgName (4, Bigint(2), Bigint(5), Bigint(4), Bigint(10));
  77. const ObjId orgUnitName (4, Bigint(2), Bigint(5), Bigint(4), Bigint(11));
  78. const ObjId title (4, Bigint(2), Bigint(5), Bigint(4), Bigint(12));
  79. // From X.509
  80. const ObjId rsa
  81. (5, Bigint(2), Bigint(5), Bigint(8), Bigint(1), Bigint(1));
  82. const ObjId sqMod_n
  83. (5, Bigint(2), Bigint(5), Bigint(8), Bigint(2), Bigint(1));
  84. const ObjId sqMod_nWithRSA 
  85. (5, Bigint(2), Bigint(5), Bigint(8), Bigint(3), Bigint(1));
  86. // From 1994 Open Systems Environment Implementor's Workshop (OIW)
  87. // message digest algorithms
  88. const ObjId md2
  89. (6, Bigint(1), Bigint(2), Bigint(840), Bigint("1bb8d"), Bigint(2), 
  90.     Bigint(2));
  91. const ObjId md5
  92. (6, Bigint(1), Bigint(2), Bigint(840), Bigint("1bb8d"), Bigint(2), 
  93. Bigint(5));
  94. const ObjId sha
  95. (6, Bigint(1), Bigint(3), Bigint(14), Bigint(3), Bigint(2),
  96. Bigint(18));
  97. const ObjId rsaEncryption
  98. (7, Bigint(1), Bigint(2), Bigint(840), Bigint("1bb8d"), Bigint(1), 
  99.     Bigint(1), Bigint(1));
  100. const ObjId desECB
  101. (6, Bigint(1), Bigint(3), Bigint(14), Bigint(3), Bigint(2),
  102. Bigint(6));
  103. const ObjId desCBC
  104. (6, Bigint(1), Bigint(3), Bigint(14), Bigint(3), Bigint(2),
  105. Bigint(7));
  106. const ObjId dsa
  107. (6, Bigint(1), Bigint(3), Bigint(14), Bigint(3), Bigint(2),
  108. Bigint(12));
  109. const ObjId dsaWithSHA
  110. (6, Bigint(1), Bigint(3), Bigint(14), Bigint(3), Bigint(2),
  111. Bigint(13));
  112. const ObjId dsaCommon
  113. (6, Bigint(1), Bigint(3), Bigint(14), Bigint(3), Bigint(2),
  114. Bigint(20));
  115. const ObjId dsaCommonWithSHA
  116. (6, Bigint(1), Bigint(3), Bigint(14), Bigint(3), Bigint(2),
  117. Bigint(21));
  118. const ObjId md2WithRSAEncryption
  119. (7, Bigint(1), Bigint(2), Bigint(840), Bigint("1bb8d"), Bigint(1), 
  120.     Bigint(1), Bigint(2));
  121. const ObjId md5WithRSAEncryption
  122. (7, Bigint(1), Bigint(2), Bigint(840), Bigint("1bb8d"), Bigint(1), 
  123.     Bigint(1), Bigint(4));
  124. // From PKCS #3
  125. const ObjId pkcs_3
  126. (6, Bigint(1), Bigint(2), Bigint(840), Bigint("1bb8d"), Bigint(1),
  127.     Bigint(3));
  128. const ObjId dhKeyAgreement
  129. (7, Bigint(1), Bigint(2), Bigint(840), Bigint("1bb8d"), Bigint(1),
  130.     Bigint(3), Bigint(1));
  131. // XXXX -- SunScreen v1 definition of dhKeyAgreement
  132. const ObjId sundhKeyAgreement
  133. (6, Bigint(1), Bigint(2), Bigint(840), Bigint("1bb8d"), Bigint(1),
  134.     Bigint(3));
  135. // From PKCS #5
  136. const ObjId pbeWithMD2AndDES_CBC
  137. (7, Bigint(1), Bigint(2), Bigint(840), Bigint("1bb8d"), Bigint(1), 
  138.     Bigint(5), Bigint(1));
  139. const ObjId pbeWithMD5AndDES_CBC
  140. (7, Bigint(1), Bigint(2), Bigint(840), Bigint("1bb8d"), Bigint(1), 
  141.     Bigint(5), Bigint(3));
  142. // From Sun OID Space
  143. const ObjId ipAddress
  144. (11, Bigint(1), Bigint(3), Bigint(6), Bigint(1), Bigint(4), 
  145.      Bigint(1), Bigint(42), Bigint(2), Bigint(11), Bigint(2),
  146. Bigint(1));
  147. /*
  148.  * Macro to decode OIDs
  149.  */
  150. #define OBJECT_IDENTIFIER(oid)         
  151. {              
  152. retval = asn1_der_decode_obj_id(der_stream, oid);     
  153.      if (retval < 0) {        
  154. /* printf("OBJECT-ID decode:"); */       
  155. return (retval);       
  156.      }       
  157.     }
  158. // C++ linkage
  159. extern int asn1_der_decode_obj_id(Bstream&, ObjId&);
  160. extern Bstream asn1_der_encode_obj_id(const ObjId&);
  161. #endif OBJID_H