1 module hunt.security.x509.CRLReasonCodeExtension;
2 
3 import hunt.security.cert.CRLReason;
4 import hunt.security.x509.CertAttrSet;
5 
6 /**
7  * The reasonCode is a non-critical CRL entry extension that identifies
8  * the reason for the certificate revocation.
9  * @author Hemma Prafullchandra
10  * @see java.security.cert.CRLReason
11  * @see Extension
12  * @see CertAttrSet
13  */
14 // class CRLReasonCodeExtension : Extension, CertAttrSet!String {
15 
16 //     /**
17 //      * Attribute name
18 //      */
19 //     enum String NAME = "CRLReasonCode";
20 //     enum String REASON = "reason";
21 
22 //     private static CRLReason[] values = CRLReason.values();
23 
24 //     private int reasonCode = 0;
25 
26 //     private void encodeThis() {
27 //         if (reasonCode == 0) {
28 //             this.extensionValue = null;
29 //             return;
30 //         }
31 //         DerOutputStream dos = new DerOutputStream();
32 //         dos.putEnumerated(reasonCode);
33 //         this.extensionValue = dos.toByteArray();
34 //     }
35 
36 //     /**
37 //      * Create a CRLReasonCodeExtension with the passed in reason.
38 //      * Criticality automatically set to false.
39 //      *
40 //      * @param reason the enumerated value for the reason code.
41 //      */
42 //     this(int reason) {
43 //         this(false, reason);
44 //     }
45 
46 //     /**
47 //      * Create a CRLReasonCodeExtension with the passed in reason.
48 //      *
49 //      * @param critical true if the extension is to be treated as critical.
50 //      * @param reason the enumerated value for the reason code.
51 //      */
52 //     this(boolean critical, int reason)    {
53 //         this.extensionId = PKIXExtensions.ReasonCode_Id;
54 //         this.critical = critical;
55 //         this.reasonCode = reason;
56 //         encodeThis();
57 //     }
58 
59 //     /**
60 //      * Create the extension from the passed DER encoded value of the same.
61 //      *
62 //      * @param critical true if the extension is to be treated as critical.
63 //      * @param value an array of DER encoded bytes of the actual value.
64 //      * @exception ClassCastException if value is not an array of bytes
65 //      * @exception IOException on error.
66 //      */
67 //     this(Boolean critical, Object value)
68 //     {
69 //         this.extensionId = PKIXExtensions.ReasonCode_Id;
70 //         this.critical = critical.booleanValue();
71 //         this.extensionValue = (byte[]) value;
72 //         DerValue val = new DerValue(this.extensionValue);
73 //         this.reasonCode = val.getEnumerated();
74 //     }
75 
76 //     /**
77 //      * Set the attribute value.
78 //      */
79 //     void set(String name, Object obj) {
80 //         if (!(obj instanceof Integer)) {
81 //             throw new IOException("Attribute must be of type Integer.");
82 //         }
83 //         if (name.equalsIgnoreCase(REASON)) {
84 //             reasonCode = ((Integer)obj).intValue();
85 //         } else {
86 //             throw new IOException
87 //                 ("Name not supported by CRLReasonCodeExtension");
88 //         }
89 //         encodeThis();
90 //     }
91 
92 //     /**
93 //      * Get the attribute value.
94 //      */
95 //     Integer get(String name) {
96 //         if (name.equalsIgnoreCase(REASON)) {
97 //             return new Integer(reasonCode);
98 //         } else {
99 //             throw new IOException
100 //                 ("Name not supported by CRLReasonCodeExtension");
101 //         }
102 //     }
103 
104 //     /**
105 //      * Delete the attribute value.
106 //      */
107 //     void delete(String name) {
108 //         if (name.equalsIgnoreCase(REASON)) {
109 //             reasonCode = 0;
110 //         } else {
111 //             throw new IOException
112 //                 ("Name not supported by CRLReasonCodeExtension");
113 //         }
114 //         encodeThis();
115 //     }
116 
117 //     /**
118 //      * Returns a printable representation of the Reason code.
119 //      */
120 //     String toString() {
121 //         return super.toString() + "    Reason Code: " + getReasonCode();
122 //     }
123 
124 //     /**
125 //      * Write the extension to the DerOutputStream.
126 //      *
127 //      * @param out the DerOutputStream to write the extension to.
128 //      * @exception IOException on encoding errors.
129 //      */
130 //     void encode(OutputStream out) {
131 //         DerOutputStream  tmp = new DerOutputStream();
132 
133 //         if (this.extensionValue is null) {
134 //             this.extensionId = PKIXExtensions.ReasonCode_Id;
135 //             this.critical = false;
136 //             encodeThis();
137 //         }
138 //         super.encode(tmp);
139 //         out.write(tmp.toByteArray());
140 //     }
141 
142 //     /**
143 //      * Return an enumeration of names of attributes existing within this
144 //      * attribute.
145 //      */
146 //     Enumeration<String> getElements() {
147 //         AttributeNameEnumeration elements = new AttributeNameEnumeration();
148 //         elements.addElement(REASON);
149 
150 //         return elements.elements();
151 //     }
152 
153 //     /**
154 //      * Return the name of this attribute.
155 //      */
156 //     String getName() {
157 //         return NAME;
158 //     }
159 
160 //     /**
161 //      * Return the reason as a CRLReason enum.
162 //      */
163 //     CRLReason getReasonCode() {
164 //         // if out-of-range, return UNSPECIFIED
165 //         if (reasonCode > 0 && reasonCode < values.length) {
166 //             return values[reasonCode];
167 //         } else {
168 //             return CRLReason.UNSPECIFIED;
169 //         }
170 //     }
171 // }
172 
173