Browse Source
* commit '43c53d5affda4f7bb1c31fa2c75e73bcaf69c898': 把bouncycastle1.64修改包名后升级原来的1.60 把bouncycastle1.64修改包名后升级原来的1.60research/11.0
superman
4 years ago
1578 changed files with 151750 additions and 14217 deletions
@ -0,0 +1,292 @@
|
||||
package com.fr.third.org.bouncycastle.asn1; |
||||
|
||||
import java.io.IOException; |
||||
|
||||
/** |
||||
* Class representing the DER-type External |
||||
*/ |
||||
public abstract class ASN1External |
||||
extends ASN1Primitive |
||||
{ |
||||
protected ASN1ObjectIdentifier directReference; |
||||
protected ASN1Integer indirectReference; |
||||
protected ASN1Primitive dataValueDescriptor; |
||||
protected int encoding; |
||||
protected ASN1Primitive externalContent; |
||||
|
||||
/** |
||||
* Construct an EXTERNAL object, the input encoding vector must have exactly two elements on it. |
||||
* <p> |
||||
* Acceptable input formats are: |
||||
* <ul> |
||||
* <li> {@link ASN1ObjectIdentifier} + data {@link DERTaggedObject} (direct reference form)</li> |
||||
* <li> {@link ASN1Integer} + data {@link DERTaggedObject} (indirect reference form)</li> |
||||
* <li> Anything but {@link DERTaggedObject} + data {@link DERTaggedObject} (data value form)</li> |
||||
* </ul> |
||||
* |
||||
* @throws IllegalArgumentException if input size is wrong, or |
||||
*/ |
||||
public ASN1External(ASN1EncodableVector vector) |
||||
{ |
||||
int offset = 0; |
||||
|
||||
ASN1Primitive enc = getObjFromVector(vector, offset); |
||||
if (enc instanceof ASN1ObjectIdentifier) |
||||
{ |
||||
directReference = (ASN1ObjectIdentifier)enc; |
||||
offset++; |
||||
enc = getObjFromVector(vector, offset); |
||||
} |
||||
if (enc instanceof ASN1Integer) |
||||
{ |
||||
indirectReference = (ASN1Integer) enc; |
||||
offset++; |
||||
enc = getObjFromVector(vector, offset); |
||||
} |
||||
if (!(enc instanceof ASN1TaggedObject)) |
||||
{ |
||||
dataValueDescriptor = (ASN1Primitive) enc; |
||||
offset++; |
||||
enc = getObjFromVector(vector, offset); |
||||
} |
||||
|
||||
if (vector.size() != offset + 1) |
||||
{ |
||||
throw new IllegalArgumentException("input vector too large"); |
||||
} |
||||
|
||||
if (!(enc instanceof ASN1TaggedObject)) |
||||
{ |
||||
throw new IllegalArgumentException("No tagged object found in vector. Structure doesn't seem to be of type External"); |
||||
} |
||||
ASN1TaggedObject obj = (ASN1TaggedObject)enc; |
||||
setEncoding(obj.getTagNo()); |
||||
externalContent = obj.getObject(); |
||||
} |
||||
|
||||
private ASN1Primitive getObjFromVector(ASN1EncodableVector v, int index) |
||||
{ |
||||
if (v.size() <= index) |
||||
{ |
||||
throw new IllegalArgumentException("too few objects in input vector"); |
||||
} |
||||
|
||||
return v.get(index).toASN1Primitive(); |
||||
} |
||||
|
||||
/** |
||||
* Creates a new instance of External |
||||
* See X.690 for more informations about the meaning of these parameters |
||||
* @param directReference The direct reference or <code>null</code> if not set. |
||||
* @param indirectReference The indirect reference or <code>null</code> if not set. |
||||
* @param dataValueDescriptor The data value descriptor or <code>null</code> if not set. |
||||
* @param externalData The external data in its encoded form. |
||||
*/ |
||||
public ASN1External(ASN1ObjectIdentifier directReference, ASN1Integer indirectReference, ASN1Primitive dataValueDescriptor, DERTaggedObject externalData) |
||||
{ |
||||
this(directReference, indirectReference, dataValueDescriptor, externalData.getTagNo(), externalData.toASN1Primitive()); |
||||
} |
||||
|
||||
/** |
||||
* Creates a new instance of External. |
||||
* See X.690 for more informations about the meaning of these parameters |
||||
* @param directReference The direct reference or <code>null</code> if not set. |
||||
* @param indirectReference The indirect reference or <code>null</code> if not set. |
||||
* @param dataValueDescriptor The data value descriptor or <code>null</code> if not set. |
||||
* @param encoding The encoding to be used for the external data |
||||
* @param externalData The external data |
||||
*/ |
||||
public ASN1External(ASN1ObjectIdentifier directReference, ASN1Integer indirectReference, ASN1Primitive dataValueDescriptor, int encoding, ASN1Primitive externalData) |
||||
{ |
||||
setDirectReference(directReference); |
||||
setIndirectReference(indirectReference); |
||||
setDataValueDescriptor(dataValueDescriptor); |
||||
setEncoding(encoding); |
||||
setExternalContent(externalData.toASN1Primitive()); |
||||
} |
||||
|
||||
ASN1Primitive toDERObject() |
||||
{ |
||||
return new DERExternal(directReference, indirectReference, dataValueDescriptor, encoding, externalContent); |
||||
} |
||||
|
||||
ASN1Primitive toDLObject() |
||||
{ |
||||
return new DLExternal(directReference, indirectReference, dataValueDescriptor, encoding, externalContent); |
||||
} |
||||
|
||||
/* (non-Javadoc) |
||||
* @see java.lang.Object#hashCode() |
||||
*/ |
||||
public int hashCode() |
||||
{ |
||||
int ret = 0; |
||||
if (directReference != null) |
||||
{ |
||||
ret = directReference.hashCode(); |
||||
} |
||||
if (indirectReference != null) |
||||
{ |
||||
ret ^= indirectReference.hashCode(); |
||||
} |
||||
if (dataValueDescriptor != null) |
||||
{ |
||||
ret ^= dataValueDescriptor.hashCode(); |
||||
} |
||||
ret ^= externalContent.hashCode(); |
||||
return ret; |
||||
} |
||||
|
||||
boolean isConstructed() |
||||
{ |
||||
return true; |
||||
} |
||||
|
||||
int encodedLength() |
||||
throws IOException |
||||
{ |
||||
return this.getEncoded().length; |
||||
} |
||||
|
||||
/* (non-Javadoc) |
||||
* @see com.fr.third.org.bouncycastle.asn1.ASN1Primitive#asn1Equals(com.fr.third.org.bouncycastle.asn1.ASN1Primitive) |
||||
*/ |
||||
boolean asn1Equals(ASN1Primitive o) |
||||
{ |
||||
if (!(o instanceof ASN1External)) |
||||
{ |
||||
return false; |
||||
} |
||||
if (this == o) |
||||
{ |
||||
return true; |
||||
} |
||||
ASN1External other = (ASN1External)o; |
||||
if (directReference != null) |
||||
{ |
||||
if (other.directReference == null || !other.directReference.equals(directReference)) |
||||
{ |
||||
return false; |
||||
} |
||||
} |
||||
if (indirectReference != null) |
||||
{ |
||||
if (other.indirectReference == null || !other.indirectReference.equals(indirectReference)) |
||||
{ |
||||
return false; |
||||
} |
||||
} |
||||
if (dataValueDescriptor != null) |
||||
{ |
||||
if (other.dataValueDescriptor == null || !other.dataValueDescriptor.equals(dataValueDescriptor)) |
||||
{ |
||||
return false; |
||||
} |
||||
} |
||||
return externalContent.equals(other.externalContent); |
||||
} |
||||
|
||||
/** |
||||
* Returns the data value descriptor |
||||
* @return The descriptor |
||||
*/ |
||||
public ASN1Primitive getDataValueDescriptor() |
||||
{ |
||||
return dataValueDescriptor; |
||||
} |
||||
|
||||
/** |
||||
* Returns the direct reference of the external element |
||||
* @return The reference |
||||
*/ |
||||
public ASN1ObjectIdentifier getDirectReference() |
||||
{ |
||||
return directReference; |
||||
} |
||||
|
||||
/** |
||||
* Returns the encoding of the content. Valid values are |
||||
* <ul> |
||||
* <li><code>0</code> single-ASN1-type</li> |
||||
* <li><code>1</code> OCTET STRING</li> |
||||
* <li><code>2</code> BIT STRING</li> |
||||
* </ul> |
||||
* @return The encoding |
||||
*/ |
||||
public int getEncoding() |
||||
{ |
||||
return encoding; |
||||
} |
||||
|
||||
/** |
||||
* Returns the content of this element |
||||
* @return The content |
||||
*/ |
||||
public ASN1Primitive getExternalContent() |
||||
{ |
||||
return externalContent; |
||||
} |
||||
|
||||
/** |
||||
* Returns the indirect reference of this element |
||||
* @return The reference |
||||
*/ |
||||
public ASN1Integer getIndirectReference() |
||||
{ |
||||
return indirectReference; |
||||
} |
||||
|
||||
/** |
||||
* Sets the data value descriptor |
||||
* @param dataValueDescriptor The descriptor |
||||
*/ |
||||
private void setDataValueDescriptor(ASN1Primitive dataValueDescriptor) |
||||
{ |
||||
this.dataValueDescriptor = dataValueDescriptor; |
||||
} |
||||
|
||||
/** |
||||
* Sets the direct reference of the external element |
||||
* @param directReferemce The reference |
||||
*/ |
||||
private void setDirectReference(ASN1ObjectIdentifier directReferemce) |
||||
{ |
||||
this.directReference = directReferemce; |
||||
} |
||||
|
||||
/** |
||||
* Sets the encoding of the content. Valid values are |
||||
* <ul> |
||||
* <li><code>0</code> single-ASN1-type</li> |
||||
* <li><code>1</code> OCTET STRING</li> |
||||
* <li><code>2</code> BIT STRING</li> |
||||
* </ul> |
||||
* @param encoding The encoding |
||||
*/ |
||||
private void setEncoding(int encoding) |
||||
{ |
||||
if (encoding < 0 || encoding > 2) |
||||
{ |
||||
throw new IllegalArgumentException("invalid encoding value: " + encoding); |
||||
} |
||||
this.encoding = encoding; |
||||
} |
||||
|
||||
/** |
||||
* Sets the content of this element |
||||
* @param externalContent The content |
||||
*/ |
||||
private void setExternalContent(ASN1Primitive externalContent) |
||||
{ |
||||
this.externalContent = externalContent; |
||||
} |
||||
|
||||
/** |
||||
* Sets the indirect reference of this element |
||||
* @param indirectReference The reference |
||||
*/ |
||||
private void setIndirectReference(ASN1Integer indirectReference) |
||||
{ |
||||
this.indirectReference = indirectReference; |
||||
} |
||||
} |
@ -1,51 +1,27 @@
|
||||
package com.fr.third.org.bouncycastle.asn1; |
||||
|
||||
import java.io.IOException; |
||||
import java.io.OutputStream; |
||||
|
||||
/** |
||||
* A class which writes indefinite and definite length objects. Objects which specify DER will be encoded accordingly, but DL or BER |
||||
* objects will be encoded as defined. |
||||
* A class which writes indefinite and definite length objects. Objects which specify DER will be |
||||
* encoded accordingly, but DL or BER objects will be encoded as defined. |
||||
* |
||||
* @deprecated Will be removed from public API. |
||||
*/ |
||||
public class BEROutputStream |
||||
extends DEROutputStream |
||||
extends ASN1OutputStream |
||||
{ |
||||
/** |
||||
* Base constructor. |
||||
* |
||||
* @param os target output stream. |
||||
*/ |
||||
public BEROutputStream( |
||||
OutputStream os) |
||||
{ |
||||
super(os); |
||||
} |
||||
|
||||
/** |
||||
* Write out an ASN.1 object. |
||||
* @param os |
||||
* target output stream. |
||||
* |
||||
* @param obj the object to be encoded. |
||||
* @throws IOException if there is an issue on encoding or output of the object. |
||||
* @deprecated Use {@link ASN1OutputStream#create(OutputStream, String)} with |
||||
* {@link ASN1Encoding#BER} instead. |
||||
*/ |
||||
public void writeObject( |
||||
Object obj) |
||||
throws IOException |
||||
{ |
||||
if (obj == null) |
||||
public BEROutputStream(OutputStream os) |
||||
{ |
||||
writeNull(); |
||||
} |
||||
else if (obj instanceof ASN1Primitive) |
||||
{ |
||||
((ASN1Primitive)obj).encode(this); |
||||
} |
||||
else if (obj instanceof ASN1Encodable) |
||||
{ |
||||
((ASN1Encodable)obj).toASN1Primitive().encode(this); |
||||
} |
||||
else |
||||
{ |
||||
throw new IOException("object not BEREncodable"); |
||||
} |
||||
super(os); |
||||
} |
||||
} |
||||
|
@ -1,22 +0,0 @@
|
||||
package com.fr.third.org.bouncycastle.asn1; |
||||
|
||||
/** |
||||
* @deprecated use ASN1Boolean |
||||
*/ |
||||
public class DERBoolean |
||||
extends ASN1Boolean |
||||
{ |
||||
/** |
||||
* @deprecated use getInstance(boolean) method. |
||||
* @param value |
||||
*/ |
||||
public DERBoolean(boolean value) |
||||
{ |
||||
super(value); |
||||
} |
||||
|
||||
DERBoolean(byte[] value) |
||||
{ |
||||
super(value); |
||||
} |
||||
} |
@ -0,0 +1,124 @@
|
||||
package com.fr.third.org.bouncycastle.asn1; |
||||
|
||||
import java.io.ByteArrayOutputStream; |
||||
import java.io.IOException; |
||||
|
||||
/** |
||||
* A DER encoding version of an application specific object. |
||||
*/ |
||||
public class DLApplicationSpecific |
||||
extends ASN1ApplicationSpecific |
||||
{ |
||||
DLApplicationSpecific( |
||||
boolean isConstructed, |
||||
int tag, |
||||
byte[] octets) |
||||
{ |
||||
super(isConstructed, tag, octets); |
||||
} |
||||
|
||||
/** |
||||
* Create an application specific object from the passed in data. This will assume |
||||
* the data does not represent a constructed object. |
||||
* |
||||
* @param tag the tag number for this object. |
||||
* @param octets the encoding of the object's body. |
||||
*/ |
||||
public DLApplicationSpecific( |
||||
int tag, |
||||
byte[] octets) |
||||
{ |
||||
this(false, tag, octets); |
||||
} |
||||
|
||||
/** |
||||
* Create an application specific object with a tagging of explicit/constructed. |
||||
* |
||||
* @param tag the tag number for this object. |
||||
* @param object the object to be contained. |
||||
*/ |
||||
public DLApplicationSpecific( |
||||
int tag, |
||||
ASN1Encodable object) |
||||
throws IOException |
||||
{ |
||||
this(true, tag, object); |
||||
} |
||||
|
||||
/** |
||||
* Create an application specific object with the tagging style given by the value of constructed. |
||||
* |
||||
* @param constructed true if the object is constructed. |
||||
* @param tag the tag number for this object. |
||||
* @param object the object to be contained. |
||||
*/ |
||||
public DLApplicationSpecific( |
||||
boolean constructed, |
||||
int tag, |
||||
ASN1Encodable object) |
||||
throws IOException |
||||
{ |
||||
super(constructed || object.toASN1Primitive().isConstructed(), tag, getEncoding(constructed, object)); |
||||
} |
||||
|
||||
private static byte[] getEncoding(boolean explicit, ASN1Encodable object) |
||||
throws IOException |
||||
{ |
||||
byte[] data = object.toASN1Primitive().getEncoded(ASN1Encoding.DL); |
||||
|
||||
if (explicit) |
||||
{ |
||||
return data; |
||||
} |
||||
else |
||||
{ |
||||
int lenBytes = getLengthOfHeader(data); |
||||
byte[] tmp = new byte[data.length - lenBytes]; |
||||
System.arraycopy(data, lenBytes, tmp, 0, tmp.length); |
||||
return tmp; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Create an application specific object which is marked as constructed |
||||
* |
||||
* @param tagNo the tag number for this object. |
||||
* @param vec the objects making up the application specific object. |
||||
*/ |
||||
public DLApplicationSpecific(int tagNo, ASN1EncodableVector vec) |
||||
{ |
||||
super(true, tagNo, getEncodedVector(vec)); |
||||
} |
||||
|
||||
private static byte[] getEncodedVector(ASN1EncodableVector vec) |
||||
{ |
||||
ByteArrayOutputStream bOut = new ByteArrayOutputStream(); |
||||
|
||||
for (int i = 0; i != vec.size(); i++) |
||||
{ |
||||
try |
||||
{ |
||||
bOut.write(((ASN1Object)vec.get(i)).getEncoded(ASN1Encoding.DL)); |
||||
} |
||||
catch (IOException e) |
||||
{ |
||||
throw new ASN1ParsingException("malformed object: " + e, e); |
||||
} |
||||
} |
||||
return bOut.toByteArray(); |
||||
} |
||||
|
||||
/* (non-Javadoc) |
||||
* @see com.fr.third.org.bouncycastle.asn1.ASN1Primitive#encode(com.fr.third.org.bouncycastle.asn1.DEROutputStream) |
||||
*/ |
||||
void encode(ASN1OutputStream out, boolean withTag) throws IOException |
||||
{ |
||||
int flags = BERTags.APPLICATION; |
||||
if (isConstructed) |
||||
{ |
||||
flags |= BERTags.CONSTRUCTED; |
||||
} |
||||
|
||||
out.writeEncoded(withTag, flags, tag, octets); |
||||
} |
||||
} |
@ -0,0 +1,90 @@
|
||||
package com.fr.third.org.bouncycastle.asn1; |
||||
|
||||
import java.io.ByteArrayOutputStream; |
||||
import java.io.IOException; |
||||
|
||||
/** |
||||
* Class representing the Definite-Length-type External |
||||
*/ |
||||
public class DLExternal |
||||
extends ASN1External |
||||
{ |
||||
/** |
||||
* Construct a Definite-Length EXTERNAL object, the input encoding vector must have exactly two elements on it. |
||||
* <p> |
||||
* Acceptable input formats are: |
||||
* <ul> |
||||
* <li> {@link ASN1ObjectIdentifier} + data {@link DERTaggedObject} (direct reference form)</li> |
||||
* <li> {@link ASN1Integer} + data {@link DERTaggedObject} (indirect reference form)</li> |
||||
* <li> Anything but {@link DERTaggedObject} + data {@link DERTaggedObject} (data value form)</li> |
||||
* </ul> |
||||
* |
||||
* @throws IllegalArgumentException if input size is wrong, or |
||||
*/ |
||||
public DLExternal(ASN1EncodableVector vector) |
||||
{ |
||||
super(vector); |
||||
} |
||||
|
||||
/** |
||||
* Creates a new instance of DERExternal |
||||
* See X.690 for more informations about the meaning of these parameters |
||||
* @param directReference The direct reference or <code>null</code> if not set. |
||||
* @param indirectReference The indirect reference or <code>null</code> if not set. |
||||
* @param dataValueDescriptor The data value descriptor or <code>null</code> if not set. |
||||
* @param externalData The external data in its encoded form. |
||||
*/ |
||||
public DLExternal(ASN1ObjectIdentifier directReference, ASN1Integer indirectReference, ASN1Primitive dataValueDescriptor, DERTaggedObject externalData) |
||||
{ |
||||
this(directReference, indirectReference, dataValueDescriptor, externalData.getTagNo(), externalData.toASN1Primitive()); |
||||
} |
||||
|
||||
/** |
||||
* Creates a new instance of Definite-Length External. |
||||
* See X.690 for more informations about the meaning of these parameters |
||||
* @param directReference The direct reference or <code>null</code> if not set. |
||||
* @param indirectReference The indirect reference or <code>null</code> if not set. |
||||
* @param dataValueDescriptor The data value descriptor or <code>null</code> if not set. |
||||
* @param encoding The encoding to be used for the external data |
||||
* @param externalData The external data |
||||
*/ |
||||
public DLExternal(ASN1ObjectIdentifier directReference, ASN1Integer indirectReference, ASN1Primitive dataValueDescriptor, int encoding, ASN1Primitive externalData) |
||||
{ |
||||
super(directReference, indirectReference, dataValueDescriptor, encoding, externalData); |
||||
} |
||||
|
||||
ASN1Primitive toDLObject() |
||||
{ |
||||
return this; |
||||
} |
||||
|
||||
int encodedLength() |
||||
throws IOException |
||||
{ |
||||
return this.getEncoded().length; |
||||
} |
||||
|
||||
/* (non-Javadoc) |
||||
* @see com.fr.third.org.bouncycastle.asn1.ASN1Primitive#encode(com.fr.third.org.bouncycastle.asn1.DEROutputStream) |
||||
*/ |
||||
void encode(ASN1OutputStream out, boolean withTag) throws IOException |
||||
{ |
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
||||
if (directReference != null) |
||||
{ |
||||
baos.write(directReference.getEncoded(ASN1Encoding.DL)); |
||||
} |
||||
if (indirectReference != null) |
||||
{ |
||||
baos.write(indirectReference.getEncoded(ASN1Encoding.DL)); |
||||
} |
||||
if (dataValueDescriptor != null) |
||||
{ |
||||
baos.write(dataValueDescriptor.getEncoded(ASN1Encoding.DL)); |
||||
} |
||||
DERTaggedObject obj = new DERTaggedObject(true, encoding, externalContent); |
||||
baos.write(obj.getEncoded(ASN1Encoding.DL)); |
||||
|
||||
out.writeEncoded(withTag, BERTags.CONSTRUCTED, BERTags.EXTERNAL, baos.toByteArray()); |
||||
} |
||||
} |
@ -0,0 +1,27 @@
|
||||
package com.fr.third.org.bouncycastle.asn1; |
||||
|
||||
class DLFactory |
||||
{ |
||||
static final ASN1Sequence EMPTY_SEQUENCE = new DLSequence(); |
||||
static final ASN1Set EMPTY_SET = new DLSet(); |
||||
|
||||
static ASN1Sequence createSequence(ASN1EncodableVector v) |
||||
{ |
||||
if (v.size() < 1) |
||||
{ |
||||
return EMPTY_SEQUENCE; |
||||
} |
||||
|
||||
return new DLSequence(v); |
||||
} |
||||
|
||||
static ASN1Set createSet(ASN1EncodableVector v) |
||||
{ |
||||
if (v.size() < 1) |
||||
{ |
||||
return EMPTY_SET; |
||||
} |
||||
|
||||
return new DLSet(v); |
||||
} |
||||
} |
@ -0,0 +1,12 @@
|
||||
package com.fr.third.org.bouncycastle.asn1; |
||||
|
||||
/** |
||||
* Parser class for DL SEQUENCEs. |
||||
*/ |
||||
public class DLSequenceParser extends DERSequenceParser |
||||
{ |
||||
DLSequenceParser(ASN1StreamParser parser) |
||||
{ |
||||
super(parser); |
||||
} |
||||
} |
@ -0,0 +1,12 @@
|
||||
package com.fr.third.org.bouncycastle.asn1; |
||||
|
||||
/** |
||||
* Parser class for DL SETs. |
||||
*/ |
||||
public class DLSetParser extends DERSetParser |
||||
{ |
||||
DLSetParser(ASN1StreamParser parser) |
||||
{ |
||||
super(parser); |
||||
} |
||||
} |
@ -0,0 +1,80 @@
|
||||
package com.fr.third.org.bouncycastle.asn1; |
||||
|
||||
import java.text.ParseException; |
||||
import java.text.SimpleDateFormat; |
||||
import java.util.Date; |
||||
import java.util.HashMap; |
||||
import java.util.Locale; |
||||
import java.util.Map; |
||||
|
||||
class DateUtil |
||||
{ |
||||
private static Long ZERO = longValueOf(0); |
||||
|
||||
private static final Map localeCache = new HashMap(); |
||||
|
||||
static Locale EN_Locale = forEN(); |
||||
|
||||
private static Locale forEN() |
||||
{ |
||||
if ("en".equalsIgnoreCase(Locale.getDefault().getLanguage())) |
||||
{ |
||||
return Locale.getDefault(); |
||||
} |
||||
|
||||
Locale[] locales = Locale.getAvailableLocales(); |
||||
for (int i = 0; i != locales.length; i++) |
||||
{ |
||||
if ("en".equalsIgnoreCase(locales[i].getLanguage())) |
||||
{ |
||||
return locales[i]; |
||||
} |
||||
} |
||||
|
||||
return Locale.getDefault(); |
||||
} |
||||
|
||||
static Date epochAdjust(Date date) |
||||
throws ParseException |
||||
{ |
||||
Locale locale = Locale.getDefault(); |
||||
if (locale == null) |
||||
{ |
||||
return date; |
||||
} |
||||
|
||||
synchronized (localeCache) |
||||
{ |
||||
Long adj = (Long)localeCache.get(locale); |
||||
|
||||
if (adj == null) |
||||
{ |
||||
SimpleDateFormat dateF = new SimpleDateFormat("yyyyMMddHHmmssz"); |
||||
long v = dateF.parse("19700101000000GMT+00:00").getTime(); |
||||
|
||||
if (v == 0) |
||||
{ |
||||
adj = ZERO; |
||||
} |
||||
else |
||||
{ |
||||
adj = longValueOf(v); |
||||
} |
||||
|
||||
localeCache.put(locale, adj); |
||||
} |
||||
|
||||
if (adj != ZERO) |
||||
{ |
||||
return new Date(date.getTime() - adj.longValue()); |
||||
} |
||||
|
||||
return date; |
||||
} |
||||
} |
||||
|
||||
private static Long longValueOf(long v) |
||||
{ |
||||
return Long.valueOf(v); |
||||
} |
||||
} |
@ -0,0 +1,126 @@
|
||||
package com.fr.third.org.bouncycastle.asn1.bc; |
||||
|
||||
import com.fr.third.org.bouncycastle.asn1.ASN1EncodableVector; |
||||
import com.fr.third.org.bouncycastle.asn1.ASN1Object; |
||||
import com.fr.third.org.bouncycastle.asn1.ASN1Primitive; |
||||
import com.fr.third.org.bouncycastle.asn1.ASN1Sequence; |
||||
import com.fr.third.org.bouncycastle.asn1.ASN1TaggedObject; |
||||
import com.fr.third.org.bouncycastle.asn1.DERSequence; |
||||
import com.fr.third.org.bouncycastle.asn1.DERTaggedObject; |
||||
import com.fr.third.org.bouncycastle.asn1.x500.X500Name; |
||||
import com.fr.third.org.bouncycastle.asn1.x509.DigestInfo; |
||||
import com.fr.third.org.bouncycastle.asn1.x509.GeneralName; |
||||
import com.fr.third.org.bouncycastle.asn1.x509.GeneralNames; |
||||
|
||||
/** |
||||
* Extension to tie an alternate certificate to the containing certificate. |
||||
* <pre> |
||||
* LinkedCertificate := SEQUENCE { |
||||
* digest DigestInfo, -- digest of PQC certificate |
||||
* certLocation GeneralName, -- location of PQC certificate |
||||
* certIssuer [0] Name OPTIONAL, -- issuer of PQC cert (if different from current certificate) |
||||
* cACerts [1] GeneralNames OPTIONAL, -- CA certificates for PQC cert (one of more locations) |
||||
* } |
||||
* </pre> |
||||
*/ |
||||
public class LinkedCertificate |
||||
extends ASN1Object |
||||
{ |
||||
private final DigestInfo digest; |
||||
private final GeneralName certLocation; |
||||
|
||||
private X500Name certIssuer; |
||||
private GeneralNames cACerts; |
||||
|
||||
public LinkedCertificate(DigestInfo digest, GeneralName certLocation) |
||||
{ |
||||
this(digest, certLocation, null, null); |
||||
} |
||||
|
||||
public LinkedCertificate(DigestInfo digest, GeneralName certLocation, X500Name certIssuer, GeneralNames cACerts) |
||||
{ |
||||
this.digest = digest; |
||||
this.certLocation = certLocation; |
||||
this.certIssuer = certIssuer; |
||||
this.cACerts = cACerts; |
||||
} |
||||
|
||||
private LinkedCertificate(ASN1Sequence seq) |
||||
{ |
||||
this.digest = DigestInfo.getInstance(seq.getObjectAt(0)); |
||||
this.certLocation = GeneralName.getInstance(seq.getObjectAt(1)); |
||||
|
||||
if (seq.size() > 2) |
||||
{ |
||||
for (int i = 2; i != seq.size(); i++) |
||||
{ |
||||
ASN1TaggedObject tagged = ASN1TaggedObject.getInstance(seq.getObjectAt(i)); |
||||
|
||||
switch (tagged.getTagNo()) |
||||
{ |
||||
case 0: |
||||
certIssuer = X500Name.getInstance(tagged, false); |
||||
break; |
||||
case 1: |
||||
cACerts = GeneralNames.getInstance(tagged, false); |
||||
break; |
||||
default: |
||||
throw new IllegalArgumentException("unknown tag in tagged field"); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
public static LinkedCertificate getInstance(Object o) |
||||
{ |
||||
if (o instanceof LinkedCertificate) |
||||
{ |
||||
return (LinkedCertificate)o; |
||||
} |
||||
else if (o != null) |
||||
{ |
||||
return new LinkedCertificate(ASN1Sequence.getInstance(o)); |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
|
||||
public DigestInfo getDigest() |
||||
{ |
||||
return digest; |
||||
} |
||||
|
||||
public GeneralName getCertLocation() |
||||
{ |
||||
return certLocation; |
||||
} |
||||
|
||||
public X500Name getCertIssuer() |
||||
{ |
||||
return certIssuer; |
||||
} |
||||
|
||||
public GeneralNames getCACerts() |
||||
{ |
||||
return cACerts; |
||||
} |
||||
|
||||
public ASN1Primitive toASN1Primitive() |
||||
{ |
||||
ASN1EncodableVector v = new ASN1EncodableVector(4); |
||||
|
||||
v.add(digest); |
||||
v.add(certLocation); |
||||
|
||||
if (certIssuer != null) |
||||
{ |
||||
v.add(new DERTaggedObject(false, 0, certIssuer)); |
||||
} |
||||
if (cACerts != null) |
||||
{ |
||||
v.add(new DERTaggedObject(false, 1, cACerts)); |
||||
} |
||||
|
||||
return new DERSequence(v); |
||||
} |
||||
} |
@ -0,0 +1,117 @@
|
||||
package com.fr.third.org.bouncycastle.asn1.bc; |
||||
|
||||
import com.fr.third.org.bouncycastle.asn1.ASN1BitString; |
||||
import com.fr.third.org.bouncycastle.asn1.ASN1EncodableVector; |
||||
import com.fr.third.org.bouncycastle.asn1.ASN1Object; |
||||
import com.fr.third.org.bouncycastle.asn1.ASN1Primitive; |
||||
import com.fr.third.org.bouncycastle.asn1.ASN1Sequence; |
||||
import com.fr.third.org.bouncycastle.asn1.ASN1TaggedObject; |
||||
import com.fr.third.org.bouncycastle.asn1.DERBitString; |
||||
import com.fr.third.org.bouncycastle.asn1.DERSequence; |
||||
import com.fr.third.org.bouncycastle.asn1.DERTaggedObject; |
||||
import com.fr.third.org.bouncycastle.asn1.x509.AlgorithmIdentifier; |
||||
import com.fr.third.org.bouncycastle.asn1.x509.Certificate; |
||||
import com.fr.third.org.bouncycastle.util.Arrays; |
||||
|
||||
/** |
||||
* <pre> |
||||
* SignatureCheck ::= SEQUENCE { |
||||
* signatureAlgorithm AlgorithmIdentifier, |
||||
* certificates [0] EXPLICIT Certificates OPTIONAL, |
||||
* signatureValue BIT STRING |
||||
* } |
||||
* |
||||
* Certificates ::= SEQUENCE OF Certificate |
||||
* </pre> |
||||
*/ |
||||
public class SignatureCheck |
||||
extends ASN1Object |
||||
{ |
||||
private final AlgorithmIdentifier signatureAlgorithm; |
||||
private final ASN1Sequence certificates; |
||||
private final ASN1BitString signatureValue; |
||||
|
||||
public SignatureCheck(AlgorithmIdentifier signatureAlgorithm, byte[] signature) |
||||
{ |
||||
this.signatureAlgorithm = signatureAlgorithm; |
||||
this.certificates = null; |
||||
this.signatureValue = new DERBitString(Arrays.clone(signature)); |
||||
} |
||||
|
||||
public SignatureCheck(AlgorithmIdentifier signatureAlgorithm, Certificate[] certificates, byte[] signature) |
||||
{ |
||||
this.signatureAlgorithm = signatureAlgorithm; |
||||
this.certificates = new DERSequence(certificates); |
||||
this.signatureValue = new DERBitString(Arrays.clone(signature)); |
||||
} |
||||
|
||||
private SignatureCheck(ASN1Sequence seq) |
||||
{ |
||||
this.signatureAlgorithm = AlgorithmIdentifier.getInstance(seq.getObjectAt(0)); |
||||
int index = 1; |
||||
if (seq.getObjectAt(1) instanceof ASN1TaggedObject) |
||||
{ |
||||
this.certificates = ASN1Sequence.getInstance(ASN1TaggedObject.getInstance(seq.getObjectAt(index++)).getObject()); |
||||
} |
||||
else |
||||
{ |
||||
this.certificates = null; |
||||
} |
||||
this.signatureValue = DERBitString.getInstance(seq.getObjectAt(index)); |
||||
} |
||||
|
||||
public static SignatureCheck getInstance(Object o) |
||||
{ |
||||
if (o instanceof SignatureCheck) |
||||
{ |
||||
return (SignatureCheck)o; |
||||
} |
||||
else if (o != null) |
||||
{ |
||||
return new SignatureCheck(ASN1Sequence.getInstance(o)); |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
|
||||
public ASN1BitString getSignature() |
||||
{ |
||||
return new DERBitString(signatureValue.getBytes(), signatureValue.getPadBits()); |
||||
} |
||||
|
||||
public AlgorithmIdentifier getSignatureAlgorithm() |
||||
{ |
||||
return signatureAlgorithm; |
||||
} |
||||
|
||||
public Certificate[] getCertificates() |
||||
{ |
||||
if (certificates == null) |
||||
{ |
||||
return null; |
||||
} |
||||
|
||||
Certificate[] certs = new Certificate[certificates.size()]; |
||||
|
||||
for (int i = 0; i != certs.length; i++) |
||||
{ |
||||
certs[i] = Certificate.getInstance(certificates.getObjectAt(i)); |
||||
} |
||||
|
||||
return certs; |
||||
} |
||||
|
||||
public ASN1Primitive toASN1Primitive() |
||||
{ |
||||
ASN1EncodableVector v = new ASN1EncodableVector(3); |
||||
|
||||
v.add(signatureAlgorithm); |
||||
if (certificates != null) |
||||
{ |
||||
v.add(new DERTaggedObject(0, certificates)); |
||||
} |
||||
v.add(signatureValue); |
||||
|
||||
return new DERSequence(v); |
||||
} |
||||
} |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue