| 1 |
/* |
| 2 |
* Copyright 1999-2010 University of Chicago |
| 3 |
* |
| 4 |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in |
| 5 |
* compliance with the License. You may obtain a copy of the License at |
| 6 |
* |
| 7 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
* |
| 9 |
* Unless required by applicable law or agreed to in writing, software distributed under the License is |
| 10 |
* distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 11 |
* express or implied. |
| 12 |
* |
| 13 |
* See the License for the specific language governing permissions and limitations under the License. |
| 14 |
*/ |
| 15 |
package org.globus.gsi; |
| 16 |
|
| 17 |
import org.globus.util.I18n; |
| 18 |
|
| 19 |
/** |
| 20 |
* Represents an X.509 extension. It is used to create X.509 extensions |
| 21 |
* and pass them in a map during certificate generation. |
| 22 |
*/ |
| 23 |
public class X509Extension { |
| 24 |
|
| 25 |
protected boolean critical; |
| 26 |
protected byte[] value; |
| 27 |
protected String oid; |
| 28 |
|
| 29 |
private static I18n i18n = |
| 30 |
I18n.getI18n("org.globus.gsi.errors", |
| 31 |
X509Extension.class.getClassLoader()); |
| 32 |
|
| 33 |
/** |
| 34 |
* Creates a X509Extension object with specified oid. |
| 35 |
* The extension has no value and is marked as noncritical. |
| 36 |
* |
| 37 |
* @param oid the oid of the extension |
| 38 |
*/ |
| 39 |
public X509Extension(String oid) { |
| 40 |
this(oid, false, null); |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Creates a X509Extension object with specified oid and value. |
| 45 |
* The extension is marked as noncritical. |
| 46 |
* |
| 47 |
* @param oid the oid of the extension |
| 48 |
* @param value the actual value of the extension (not octet string |
| 49 |
* encoded). The value can be null. |
| 50 |
*/ |
| 51 |
public X509Extension(String oid, byte[] value) { |
| 52 |
this(oid, false, value); |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Creates a X509Extension object with specified oid, critical property, |
| 57 |
* and value. |
| 58 |
* |
| 59 |
* @param oid the oid of the extension |
| 60 |
* @param critical the critical value. |
| 61 |
* @param value the actual value of the extension (not octet string |
| 62 |
* encoded). The value can be null. |
| 63 |
*/ |
| 64 |
public X509Extension(String oid, boolean critical, byte[] value) { |
| 65 |
if (oid == null) { |
| 66 |
throw new IllegalArgumentException(i18n.getMessage("oidNull")); |
| 67 |
} |
| 68 |
this.oid = oid; |
| 69 |
this.critical = critical; |
| 70 |
this.value = value; |
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* Sets the oid of this extension. |
| 75 |
* |
| 76 |
* @param oid the oid of this extension. Cannot not null. |
| 77 |
*/ |
| 78 |
public void setOid(String oid) { |
| 79 |
if (oid == null) { |
| 80 |
throw new IllegalArgumentException(i18n.getMessage("oidNull")); |
| 81 |
} |
| 82 |
this.oid = oid; |
| 83 |
} |
| 84 |
|
| 85 |
/** |
| 86 |
* Returns the oid of this extension. |
| 87 |
* |
| 88 |
* @return the oid of this extension. Always non-null. |
| 89 |
*/ |
| 90 |
public String getOid() { |
| 91 |
return this.oid; |
| 92 |
} |
| 93 |
|
| 94 |
/** |
| 95 |
* Sets the extension as critical or noncritical. |
| 96 |
* |
| 97 |
* @param critical the critical value. |
| 98 |
*/ |
| 99 |
public void setCritical(boolean critical) { |
| 100 |
this.critical = critical; |
| 101 |
} |
| 102 |
|
| 103 |
/** |
| 104 |
* Determines whether or not this extension is critical. |
| 105 |
* |
| 106 |
* @return true if extension is critical, false otherwise. |
| 107 |
*/ |
| 108 |
public boolean isCritical() { |
| 109 |
return this.critical; |
| 110 |
} |
| 111 |
|
| 112 |
/** |
| 113 |
* Sets the actual value of the extension (not octet string encoded). |
| 114 |
* |
| 115 |
* @param value the actual value of the extension. Can be null. |
| 116 |
*/ |
| 117 |
public void setValue(byte [] value) { |
| 118 |
this.value = value; |
| 119 |
} |
| 120 |
|
| 121 |
/** |
| 122 |
* Returns the actual value of the extension (not octet string encoded) |
| 123 |
* |
| 124 |
* @return the actual value of the extension (not octet string encoded). |
| 125 |
* Null if value not set. |
| 126 |
*/ |
| 127 |
public byte[] getValue() { |
| 128 |
return this.value; |
| 129 |
} |
| 130 |
} |