Browse Source
* commit 'a1ad3bb2ed99f57f6df2bd21c92650be03429932': DEC-19773 refactor: 升级bouncycastle库research/10.0
superman
3 years ago
1148 changed files with 17272 additions and 143917 deletions
@ -1,2 +1,2 @@ |
|||||||
版本:1.64<br> |
版本:1.67<br> |
||||||
源码:https://www.bouncycastle.org/latest_releases.html<br> |
源码:https://www.bouncycastle.org/latest_releases.html<br> |
@ -1,144 +0,0 @@ |
|||||||
package com.fr.third.org.bouncycastle.asn1; |
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream; |
|
||||||
import java.io.IOException; |
|
||||||
import java.util.Enumeration; |
|
||||||
import java.util.Vector; |
|
||||||
|
|
||||||
/** |
|
||||||
* @deprecated use BEROctetString |
|
||||||
*/ |
|
||||||
public class BERConstructedOctetString |
|
||||||
extends BEROctetString |
|
||||||
{ |
|
||||||
private static final int MAX_LENGTH = 1000; |
|
||||||
|
|
||||||
/** |
|
||||||
* convert a vector of octet strings into a single byte string |
|
||||||
*/ |
|
||||||
static private byte[] toBytes( |
|
||||||
Vector octs) |
|
||||||
{ |
|
||||||
ByteArrayOutputStream bOut = new ByteArrayOutputStream(); |
|
||||||
|
|
||||||
for (int i = 0; i != octs.size(); i++) |
|
||||||
{ |
|
||||||
try |
|
||||||
{ |
|
||||||
DEROctetString o = (DEROctetString)octs.elementAt(i); |
|
||||||
|
|
||||||
bOut.write(o.getOctets()); |
|
||||||
} |
|
||||||
catch (ClassCastException e) |
|
||||||
{ |
|
||||||
throw new IllegalArgumentException(octs.elementAt(i).getClass().getName() + " found in input should only contain DEROctetString"); |
|
||||||
} |
|
||||||
catch (IOException e) |
|
||||||
{ |
|
||||||
throw new IllegalArgumentException("exception converting octets " + e.toString()); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
return bOut.toByteArray(); |
|
||||||
} |
|
||||||
|
|
||||||
private Vector octs; |
|
||||||
|
|
||||||
/** |
|
||||||
* @param string the octets making up the octet string. |
|
||||||
*/ |
|
||||||
public BERConstructedOctetString( |
|
||||||
byte[] string) |
|
||||||
{ |
|
||||||
super(string); |
|
||||||
} |
|
||||||
|
|
||||||
public BERConstructedOctetString( |
|
||||||
Vector octs) |
|
||||||
{ |
|
||||||
super(toBytes(octs)); |
|
||||||
|
|
||||||
this.octs = octs; |
|
||||||
} |
|
||||||
|
|
||||||
public BERConstructedOctetString( |
|
||||||
ASN1Primitive obj) |
|
||||||
{ |
|
||||||
super(toByteArray(obj)); |
|
||||||
} |
|
||||||
|
|
||||||
private static byte[] toByteArray(ASN1Primitive obj) |
|
||||||
{ |
|
||||||
try |
|
||||||
{ |
|
||||||
return obj.getEncoded(); |
|
||||||
} |
|
||||||
catch (IOException e) |
|
||||||
{ |
|
||||||
throw new IllegalArgumentException("Unable to encode object"); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public BERConstructedOctetString( |
|
||||||
ASN1Encodable obj) |
|
||||||
{ |
|
||||||
this(obj.toASN1Primitive()); |
|
||||||
} |
|
||||||
|
|
||||||
public byte[] getOctets() |
|
||||||
{ |
|
||||||
return string; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* return the DER octets that make up this string. |
|
||||||
*/ |
|
||||||
public Enumeration getObjects() |
|
||||||
{ |
|
||||||
if (octs == null) |
|
||||||
{ |
|
||||||
return generateOcts().elements(); |
|
||||||
} |
|
||||||
|
|
||||||
return octs.elements(); |
|
||||||
} |
|
||||||
|
|
||||||
private Vector generateOcts() |
|
||||||
{ |
|
||||||
Vector vec = new Vector(); |
|
||||||
for (int i = 0; i < string.length; i += MAX_LENGTH) |
|
||||||
{ |
|
||||||
int end; |
|
||||||
|
|
||||||
if (i + MAX_LENGTH > string.length) |
|
||||||
{ |
|
||||||
end = string.length; |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
end = i + MAX_LENGTH; |
|
||||||
} |
|
||||||
|
|
||||||
byte[] nStr = new byte[end - i]; |
|
||||||
|
|
||||||
System.arraycopy(string, i, nStr, 0, nStr.length); |
|
||||||
|
|
||||||
vec.addElement(new DEROctetString(nStr)); |
|
||||||
} |
|
||||||
|
|
||||||
return vec; |
|
||||||
} |
|
||||||
|
|
||||||
public static BEROctetString fromSequence(ASN1Sequence seq) |
|
||||||
{ |
|
||||||
Vector v = new Vector(); |
|
||||||
Enumeration e = seq.getObjects(); |
|
||||||
|
|
||||||
while (e.hasMoreElements()) |
|
||||||
{ |
|
||||||
v.addElement(e.nextElement()); |
|
||||||
} |
|
||||||
|
|
||||||
return new BERConstructedOctetString(v); |
|
||||||
} |
|
||||||
} |
|
@ -1,18 +0,0 @@ |
|||||||
package com.fr.third.org.bouncycastle.asn1; |
|
||||||
|
|
||||||
/** |
|
||||||
* a general class for building up a vector of DER encodable objects - |
|
||||||
* this will eventually be superseded by ASN1EncodableVector so you should |
|
||||||
* use that class in preference. |
|
||||||
*/ |
|
||||||
public class DEREncodableVector |
|
||||||
extends ASN1EncodableVector |
|
||||||
{ |
|
||||||
/** |
|
||||||
* @deprecated use ASN1EncodableVector instead. |
|
||||||
*/ |
|
||||||
public DEREncodableVector() |
|
||||||
{ |
|
||||||
|
|
||||||
} |
|
||||||
} |
|
@ -1,37 +0,0 @@ |
|||||||
package com.fr.third.org.bouncycastle.asn1; |
|
||||||
|
|
||||||
import java.math.BigInteger; |
|
||||||
|
|
||||||
/** |
|
||||||
* @deprecated Use ASN1Enumerated instead of this. |
|
||||||
*/ |
|
||||||
public class DEREnumerated |
|
||||||
extends ASN1Enumerated |
|
||||||
{ |
|
||||||
/** |
|
||||||
* @param bytes the value of this enumerated as an encoded BigInteger (signed). |
|
||||||
* @deprecated use ASN1Enumerated |
|
||||||
*/ |
|
||||||
DEREnumerated(byte[] bytes) |
|
||||||
{ |
|
||||||
super(bytes); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* @param value the value of this enumerated. |
|
||||||
* @deprecated use ASN1Enumerated |
|
||||||
*/ |
|
||||||
public DEREnumerated(BigInteger value) |
|
||||||
{ |
|
||||||
super(value); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* @param value the value of this enumerated. |
|
||||||
* @deprecated use ASN1Enumerated |
|
||||||
*/ |
|
||||||
public DEREnumerated(int value) |
|
||||||
{ |
|
||||||
super(value); |
|
||||||
} |
|
||||||
} |
|
@ -1,30 +0,0 @@ |
|||||||
package com.fr.third.org.bouncycastle.asn1; |
|
||||||
|
|
||||||
import java.math.BigInteger; |
|
||||||
|
|
||||||
/** |
|
||||||
* @deprecated Use ASN1Integer instead of this, |
|
||||||
*/ |
|
||||||
public class DERInteger |
|
||||||
extends ASN1Integer |
|
||||||
{ |
|
||||||
/** |
|
||||||
* Constructor from a byte array containing a signed representation of the number. |
|
||||||
* |
|
||||||
* @param bytes a byte array containing the signed number.A copy is made of the byte array. |
|
||||||
*/ |
|
||||||
public DERInteger(byte[] bytes) |
|
||||||
{ |
|
||||||
super(bytes, true); |
|
||||||
} |
|
||||||
|
|
||||||
public DERInteger(BigInteger value) |
|
||||||
{ |
|
||||||
super(value); |
|
||||||
} |
|
||||||
|
|
||||||
public DERInteger(long value) |
|
||||||
{ |
|
||||||
super(value); |
|
||||||
} |
|
||||||
} |
|
@ -1,24 +0,0 @@ |
|||||||
package com.fr.third.org.bouncycastle.asn1; |
|
||||||
|
|
||||||
/** |
|
||||||
* |
|
||||||
* @deprecated Use ASN1ObjectIdentifier instead of this, |
|
||||||
*/ |
|
||||||
public class DERObjectIdentifier |
|
||||||
extends ASN1ObjectIdentifier |
|
||||||
{ |
|
||||||
public DERObjectIdentifier(String identifier) |
|
||||||
{ |
|
||||||
super(identifier); |
|
||||||
} |
|
||||||
|
|
||||||
DERObjectIdentifier(byte[] bytes) |
|
||||||
{ |
|
||||||
super(bytes); |
|
||||||
} |
|
||||||
|
|
||||||
DERObjectIdentifier(ASN1ObjectIdentifier oid, String branch) |
|
||||||
{ |
|
||||||
super(oid, branch); |
|
||||||
} |
|
||||||
} |
|
@ -1,58 +0,0 @@ |
|||||||
package com.fr.third.org.bouncycastle.asn1; |
|
||||||
|
|
||||||
import java.io.IOException; |
|
||||||
|
|
||||||
/** |
|
||||||
* @deprecated Use DLSequenceParser instead |
|
||||||
*/ |
|
||||||
public class DERSequenceParser |
|
||||||
implements ASN1SequenceParser |
|
||||||
{ |
|
||||||
private ASN1StreamParser _parser; |
|
||||||
|
|
||||||
DERSequenceParser(ASN1StreamParser parser) |
|
||||||
{ |
|
||||||
this._parser = parser; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Return the next object in the SEQUENCE. |
|
||||||
* |
|
||||||
* @return next object in SEQUENCE. |
|
||||||
* @throws IOException if there is an issue loading the object. |
|
||||||
*/ |
|
||||||
public ASN1Encodable readObject() |
|
||||||
throws IOException |
|
||||||
{ |
|
||||||
return _parser.readObject(); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Return an in memory, encodable, representation of the SEQUENCE. |
|
||||||
* |
|
||||||
* @return a DERSequence. |
|
||||||
* @throws IOException if there is an issue loading the data. |
|
||||||
*/ |
|
||||||
public ASN1Primitive getLoadedObject() |
|
||||||
throws IOException |
|
||||||
{ |
|
||||||
return new DLSequence(_parser.readVector()); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Return a DERSequence representing this parser and its contents. |
|
||||||
* |
|
||||||
* @return a DERSequence. |
|
||||||
*/ |
|
||||||
public ASN1Primitive toASN1Primitive() |
|
||||||
{ |
|
||||||
try |
|
||||||
{ |
|
||||||
return getLoadedObject(); |
|
||||||
} |
|
||||||
catch (IOException e) |
|
||||||
{ |
|
||||||
throw new IllegalStateException(e.getMessage()); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -1,58 +0,0 @@ |
|||||||
package com.fr.third.org.bouncycastle.asn1; |
|
||||||
|
|
||||||
import java.io.IOException; |
|
||||||
|
|
||||||
/** |
|
||||||
* @deprecated Use DLSetParser instead |
|
||||||
*/ |
|
||||||
public class DERSetParser |
|
||||||
implements ASN1SetParser |
|
||||||
{ |
|
||||||
private ASN1StreamParser _parser; |
|
||||||
|
|
||||||
DERSetParser(ASN1StreamParser parser) |
|
||||||
{ |
|
||||||
this._parser = parser; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Return the next object in the SET. |
|
||||||
* |
|
||||||
* @return next object in SET. |
|
||||||
* @throws IOException if there is an issue loading the object. |
|
||||||
*/ |
|
||||||
public ASN1Encodable readObject() |
|
||||||
throws IOException |
|
||||||
{ |
|
||||||
return _parser.readObject(); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Return an in memory, encodable, representation of the SET. |
|
||||||
* |
|
||||||
* @return a DERSet. |
|
||||||
* @throws IOException if there is an issue loading the data. |
|
||||||
*/ |
|
||||||
public ASN1Primitive getLoadedObject() |
|
||||||
throws IOException |
|
||||||
{ |
|
||||||
return new DLSet(_parser.readVector()); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Return a DERSet representing this parser and its contents. |
|
||||||
* |
|
||||||
* @return a DERSet |
|
||||||
*/ |
|
||||||
public ASN1Primitive toASN1Primitive() |
|
||||||
{ |
|
||||||
try |
|
||||||
{ |
|
||||||
return getLoadedObject(); |
|
||||||
} |
|
||||||
catch (IOException e) |
|
||||||
{ |
|
||||||
throw new ASN1ParsingException(e.getMessage(), e); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -1,153 +0,0 @@ |
|||||||
package com.fr.third.org.bouncycastle.asn1; |
|
||||||
|
|
||||||
import java.io.IOException; |
|
||||||
|
|
||||||
import com.fr.third.org.bouncycastle.util.Arrays; |
|
||||||
import com.fr.third.org.bouncycastle.util.Strings; |
|
||||||
|
|
||||||
/** |
|
||||||
* DER T61String (also the teletex string) - a "modern" encapsulation that uses UTF-8. If at all possible, avoid this one! It's only for emergencies. |
|
||||||
* Use UTF8String instead. |
|
||||||
* @deprecated don't use this class, introduced in error, it will be removed. |
|
||||||
*/ |
|
||||||
public class DERT61UTF8String |
|
||||||
extends ASN1Primitive |
|
||||||
implements ASN1String |
|
||||||
{ |
|
||||||
private byte[] string; |
|
||||||
|
|
||||||
/** |
|
||||||
* return a T61 string from the passed in object. UTF-8 Encoding is assumed in this case. |
|
||||||
* |
|
||||||
* @param obj a DERT61UTF8String or an object that can be converted into one. |
|
||||||
* @throws IllegalArgumentException if the object cannot be converted. |
|
||||||
* @return a DERT61UTF8String instance, or null |
|
||||||
*/ |
|
||||||
public static DERT61UTF8String getInstance( |
|
||||||
Object obj) |
|
||||||
{ |
|
||||||
if (obj instanceof DERT61String) |
|
||||||
{ |
|
||||||
return new DERT61UTF8String(((DERT61String)obj).getOctets()); |
|
||||||
} |
|
||||||
|
|
||||||
if (obj == null || obj instanceof DERT61UTF8String) |
|
||||||
{ |
|
||||||
return (DERT61UTF8String)obj; |
|
||||||
} |
|
||||||
|
|
||||||
if (obj instanceof byte[]) |
|
||||||
{ |
|
||||||
try |
|
||||||
{ |
|
||||||
return new DERT61UTF8String(((DERT61String)fromByteArray((byte[])obj)).getOctets()); |
|
||||||
} |
|
||||||
catch (Exception e) |
|
||||||
{ |
|
||||||
throw new IllegalArgumentException("encoding error in getInstance: " + e.toString()); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
throw new IllegalArgumentException("illegal object in getInstance: " + obj.getClass().getName()); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* return an T61 String from a tagged object. UTF-8 encoding is assumed in this case. |
|
||||||
* |
|
||||||
* @param obj the tagged object holding the object we want |
|
||||||
* @param explicit true if the object is meant to be explicitly |
|
||||||
* tagged false otherwise. |
|
||||||
* @throws IllegalArgumentException if the tagged object cannot |
|
||||||
* be converted. |
|
||||||
* @return a DERT61UTF8String instance, or null |
|
||||||
*/ |
|
||||||
public static DERT61UTF8String getInstance( |
|
||||||
ASN1TaggedObject obj, |
|
||||||
boolean explicit) |
|
||||||
{ |
|
||||||
ASN1Primitive o = obj.getObject(); |
|
||||||
|
|
||||||
if (explicit || o instanceof DERT61String || o instanceof DERT61UTF8String) |
|
||||||
{ |
|
||||||
return getInstance(o); |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
return new DERT61UTF8String(ASN1OctetString.getInstance(o).getOctets()); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* basic constructor - string encoded as a sequence of bytes. |
|
||||||
*/ |
|
||||||
public DERT61UTF8String( |
|
||||||
byte[] string) |
|
||||||
{ |
|
||||||
this.string = string; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* basic constructor - with string UTF8 conversion assumed. |
|
||||||
*/ |
|
||||||
public DERT61UTF8String( |
|
||||||
String string) |
|
||||||
{ |
|
||||||
this(Strings.toUTF8ByteArray(string)); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Decode the encoded string and return it, UTF8 assumed. |
|
||||||
* |
|
||||||
* @return the decoded String |
|
||||||
*/ |
|
||||||
public String getString() |
|
||||||
{ |
|
||||||
return Strings.fromUTF8ByteArray(string); |
|
||||||
} |
|
||||||
|
|
||||||
public String toString() |
|
||||||
{ |
|
||||||
return getString(); |
|
||||||
} |
|
||||||
|
|
||||||
boolean isConstructed() |
|
||||||
{ |
|
||||||
return false; |
|
||||||
} |
|
||||||
|
|
||||||
int encodedLength() |
|
||||||
{ |
|
||||||
return 1 + StreamUtil.calculateBodyLength(string.length) + string.length; |
|
||||||
} |
|
||||||
|
|
||||||
void encode(ASN1OutputStream out, boolean withTag) throws IOException |
|
||||||
{ |
|
||||||
out.writeEncoded(withTag, BERTags.T61_STRING, string); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Return the encoded string as a byte array. |
|
||||||
* |
|
||||||
* @return the actual bytes making up the encoded body of the T61 string. |
|
||||||
*/ |
|
||||||
public byte[] getOctets() |
|
||||||
{ |
|
||||||
return Arrays.clone(string); |
|
||||||
} |
|
||||||
|
|
||||||
boolean asn1Equals( |
|
||||||
ASN1Primitive o) |
|
||||||
{ |
|
||||||
if (!(o instanceof DERT61UTF8String)) |
|
||||||
{ |
|
||||||
return false; |
|
||||||
} |
|
||||||
|
|
||||||
return Arrays.areEqual(string, ((DERT61UTF8String)o).string); |
|
||||||
} |
|
||||||
|
|
||||||
public int hashCode() |
|
||||||
{ |
|
||||||
return Arrays.hashCode(string); |
|
||||||
} |
|
||||||
} |
|
@ -1,9 +0,0 @@ |
|||||||
package com.fr.third.org.bouncycastle.asn1; |
|
||||||
|
|
||||||
/** |
|
||||||
* @deprecated use BERTags |
|
||||||
*/ |
|
||||||
public interface DERTags |
|
||||||
extends BERTags |
|
||||||
{ |
|
||||||
} |
|
@ -1,12 +1,60 @@ |
|||||||
package com.fr.third.org.bouncycastle.asn1; |
package com.fr.third.org.bouncycastle.asn1; |
||||||
|
|
||||||
|
import java.io.IOException; |
||||||
|
|
||||||
/** |
/** |
||||||
* Parser class for DL SEQUENCEs. |
* Parser class for DL SEQUENCEs. |
||||||
|
* |
||||||
|
* TODO The class is only publicly visible to support 'instanceof' checks; provide an alternative |
||||||
*/ |
*/ |
||||||
public class DLSequenceParser extends DERSequenceParser |
public class DLSequenceParser |
||||||
|
implements ASN1SequenceParser |
||||||
{ |
{ |
||||||
|
private ASN1StreamParser _parser; |
||||||
|
|
||||||
DLSequenceParser(ASN1StreamParser parser) |
DLSequenceParser(ASN1StreamParser parser) |
||||||
{ |
{ |
||||||
super(parser); |
this._parser = parser; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Return the next object in the SEQUENCE. |
||||||
|
* |
||||||
|
* @return next object in SEQUENCE. |
||||||
|
* @throws IOException if there is an issue loading the object. |
||||||
|
*/ |
||||||
|
public ASN1Encodable readObject() |
||||||
|
throws IOException |
||||||
|
{ |
||||||
|
return _parser.readObject(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Return an in memory, encodable, representation of the SEQUENCE. |
||||||
|
* |
||||||
|
* @return a DLSequence. |
||||||
|
* @throws IOException if there is an issue loading the data. |
||||||
|
*/ |
||||||
|
public ASN1Primitive getLoadedObject() |
||||||
|
throws IOException |
||||||
|
{ |
||||||
|
return new DLSequence(_parser.readVector()); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Return a DLSequence representing this parser and its contents. |
||||||
|
* |
||||||
|
* @return a DLSequence. |
||||||
|
*/ |
||||||
|
public ASN1Primitive toASN1Primitive() |
||||||
|
{ |
||||||
|
try |
||||||
|
{ |
||||||
|
return getLoadedObject(); |
||||||
|
} |
||||||
|
catch (IOException e) |
||||||
|
{ |
||||||
|
throw new IllegalStateException(e.getMessage()); |
||||||
|
} |
||||||
} |
} |
||||||
} |
} |
||||||
|
@ -1,12 +1,60 @@ |
|||||||
package com.fr.third.org.bouncycastle.asn1; |
package com.fr.third.org.bouncycastle.asn1; |
||||||
|
|
||||||
|
import java.io.IOException; |
||||||
|
|
||||||
/** |
/** |
||||||
* Parser class for DL SETs. |
* Parser class for DL SETs. |
||||||
|
* |
||||||
|
* TODO The class is only publicly visible to support 'instanceof' checks; provide an alternative |
||||||
*/ |
*/ |
||||||
public class DLSetParser extends DERSetParser |
public class DLSetParser |
||||||
|
implements ASN1SetParser |
||||||
{ |
{ |
||||||
|
private ASN1StreamParser _parser; |
||||||
|
|
||||||
DLSetParser(ASN1StreamParser parser) |
DLSetParser(ASN1StreamParser parser) |
||||||
{ |
{ |
||||||
super(parser); |
this._parser = parser; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Return the next object in the SET. |
||||||
|
* |
||||||
|
* @return next object in SET. |
||||||
|
* @throws IOException if there is an issue loading the object. |
||||||
|
*/ |
||||||
|
public ASN1Encodable readObject() |
||||||
|
throws IOException |
||||||
|
{ |
||||||
|
return _parser.readObject(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Return an in memory, encodable, representation of the SET. |
||||||
|
* |
||||||
|
* @return a DLSet. |
||||||
|
* @throws IOException if there is an issue loading the data. |
||||||
|
*/ |
||||||
|
public ASN1Primitive getLoadedObject() |
||||||
|
throws IOException |
||||||
|
{ |
||||||
|
return new DLSet(_parser.readVector()); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Return a DLSet representing this parser and its contents. |
||||||
|
* |
||||||
|
* @return a DLSet |
||||||
|
*/ |
||||||
|
public ASN1Primitive toASN1Primitive() |
||||||
|
{ |
||||||
|
try |
||||||
|
{ |
||||||
|
return getLoadedObject(); |
||||||
|
} |
||||||
|
catch (IOException e) |
||||||
|
{ |
||||||
|
throw new ASN1ParsingException(e.getMessage(), e); |
||||||
|
} |
||||||
} |
} |
||||||
} |
} |
||||||
|
@ -1,5 +0,0 @@ |
|||||||
<html> |
|
||||||
<body bgcolor="#ffffff"> |
|
||||||
Support classes for the French ANSSI EC curves. |
|
||||||
</body> |
|
||||||
</html> |
|
@ -1,5 +0,0 @@ |
|||||||
<html> |
|
||||||
<body bgcolor="#ffffff"> |
|
||||||
ASN.1 classes specific to the Bouncy Castle APIs. |
|
||||||
</body> |
|
||||||
</html> |
|
@ -1,5 +0,0 @@ |
|||||||
<html> |
|
||||||
<body bgcolor="#ffffff"> |
|
||||||
ASN.1 classes specific to the Bundesamt für Sicherheit in der Informationstechnik (BSI) standards. |
|
||||||
</body> |
|
||||||
</html> |
|
@ -1,5 +0,0 @@ |
|||||||
<html> |
|
||||||
<body bgcolor="#ffffff"> |
|
||||||
Support classes for Certificate Management over CMS (CMC) - RFC 5272 and RFC 6402. |
|
||||||
</body> |
|
||||||
</html> |
|
@ -1,5 +0,0 @@ |
|||||||
<html> |
|
||||||
<body bgcolor="#ffffff"> |
|
||||||
Support classes useful for encoding and supporting PKIX-CMP as described RFC 4210. |
|
||||||
</body> |
|
||||||
</html> |
|
@ -1,5 +0,0 @@ |
|||||||
<html> |
|
||||||
<body bgcolor="#ffffff"> |
|
||||||
Support classes for CMS ECC - RFC 5753/3278. |
|
||||||
</body> |
|
||||||
</html> |
|
@ -1,5 +0,0 @@ |
|||||||
<html> |
|
||||||
<body bgcolor="#ffffff"> |
|
||||||
Support classes useful for encoding and supporting Cryptographic Message Syntax as described in PKCS#7 and RFC 3369 (formerly RFC 2630). |
|
||||||
</body> |
|
||||||
</html> |
|
@ -1,5 +0,0 @@ |
|||||||
<html> |
|
||||||
<body bgcolor="#ffffff"> |
|
||||||
Support classes useful for encoding and supporting PKIX-CRMF as described RFC 4211. |
|
||||||
</body> |
|
||||||
</html> |
|
@ -1,5 +0,0 @@ |
|||||||
<html> |
|
||||||
<body bgcolor="#ffffff"> |
|
||||||
Support classes for CRYPTO-PRO related objects - such as GOST identifiers. |
|
||||||
</body> |
|
||||||
</html> |
|
@ -1,5 +0,0 @@ |
|||||||
<html> |
|
||||||
<body bgcolor="#ffffff"> |
|
||||||
Support classes useful for encoding and processing Data Validation and Certification Server (DVCS) protocols as described in RFC 3029. |
|
||||||
</body> |
|
||||||
</html> |
|
@ -1,5 +0,0 @@ |
|||||||
<html> |
|
||||||
<body bgcolor="#ffffff"> |
|
||||||
ASN.1 classes specific to the Bundesamt für Sicherheit in der Informationstechnik (BSI) Technical Guideline Advanced Security Mechanisms for Machine Readable Travel Documents. |
|
||||||
</body> |
|
||||||
</html> |
|
@ -1,6 +0,0 @@ |
|||||||
<html> |
|
||||||
<body bgcolor="#ffffff"> |
|
||||||
Support classes useful for encoding and supporting [ESF] RFC3126 |
|
||||||
Electronic Signature Formats for long term electronic signatures. |
|
||||||
</body> |
|
||||||
</html> |
|
@ -1,5 +0,0 @@ |
|||||||
<html> |
|
||||||
<body bgcolor="#ffffff"> |
|
||||||
Support classes useful for encoding and supporting Enhanced Security Services for S/MIME as described RFC 2634 and RFC 5035. |
|
||||||
</body> |
|
||||||
</html> |
|
@ -1,5 +0,0 @@ |
|||||||
<html> |
|
||||||
<body bgcolor="#ffffff"> |
|
||||||
Support classes for Enrollment over Secure Transport (EST) - RFC 7030. |
|
||||||
</body> |
|
||||||
</html> |
|
@ -1,5 +0,0 @@ |
|||||||
<html> |
|
||||||
<body bgcolor="#ffffff"> |
|
||||||
Support classes for Chinese Standard (GM) standard curves and algorithms. |
|
||||||
</body> |
|
||||||
</html> |
|
@ -1,5 +0,0 @@ |
|||||||
<html> |
|
||||||
<body bgcolor="#ffffff"> |
|
||||||
ASN.1 classes specific to the GNU APIs and applications. |
|
||||||
</body> |
|
||||||
</html> |
|
@ -1,5 +0,0 @@ |
|||||||
<html> |
|
||||||
<body bgcolor="#ffffff"> |
|
||||||
ASN.1 classes specific to the Internet Assigned Numbers Authority (IANA). |
|
||||||
</body> |
|
||||||
</html> |
|
@ -1,5 +0,0 @@ |
|||||||
<html> |
|
||||||
<body bgcolor="#ffffff"> |
|
||||||
ICAO ASN.1 classes for electronic passport. |
|
||||||
</body> |
|
||||||
</html> |
|
@ -0,0 +1,22 @@ |
|||||||
|
package com.fr.third.org.bouncycastle.asn1.isara; |
||||||
|
|
||||||
|
import com.fr.third.org.bouncycastle.asn1.ASN1ObjectIdentifier; |
||||||
|
|
||||||
|
public interface IsaraObjectIdentifiers |
||||||
|
{ |
||||||
|
/* |
||||||
|
id-alg-xmss OBJECT IDENTIFIER ::= { itu-t(0) |
||||||
|
identified-organization(4) etsi(0) reserved(127) |
||||||
|
etsi-identified-organization(0) isara(15) algorithms(1) |
||||||
|
asymmetric(1) xmss(13) 0 } |
||||||
|
*/ |
||||||
|
static ASN1ObjectIdentifier id_alg_xmss = new ASN1ObjectIdentifier("0.4.0.127.0.15.1.1.13.0"); |
||||||
|
|
||||||
|
/* |
||||||
|
id-alg-xmssmt OBJECT IDENTIFIER ::= { itu-t(0) |
||||||
|
identified-organization(4) etsi(0) reserved(127) |
||||||
|
etsi-identified-organization(0) isara(15) algorithms(1) |
||||||
|
asymmetric(1) xmssmt(14) 0 } |
||||||
|
*/ |
||||||
|
static ASN1ObjectIdentifier id_alg_xmssmt = new ASN1ObjectIdentifier("0.4.0.127.0.15.1.1.14.0"); |
||||||
|
} |
@ -1,5 +0,0 @@ |
|||||||
<html> |
|
||||||
<body bgcolor="#ffffff"> |
|
||||||
Support classes for the ISIS-MTT profile for OCSP. |
|
||||||
</body> |
|
||||||
</html> |
|
@ -1,5 +0,0 @@ |
|||||||
<html> |
|
||||||
<body bgcolor="#ffffff"> |
|
||||||
Support classes for the ISIS-MTT Project. |
|
||||||
</body> |
|
||||||
</html> |
|
@ -1,5 +0,0 @@ |
|||||||
<html> |
|
||||||
<body bgcolor="#ffffff"> |
|
||||||
Support classes for the ISIS-MTT X.509 Certificate Extensions. |
|
||||||
</body> |
|
||||||
</html> |
|
@ -1,5 +0,0 @@ |
|||||||
<html> |
|
||||||
<body bgcolor="#ffffff"> |
|
||||||
Support classes for various ISO Standards. |
|
||||||
</body> |
|
||||||
</html> |
|
@ -1,5 +0,0 @@ |
|||||||
<html> |
|
||||||
<body bgcolor="#ffffff"> |
|
||||||
Support classes for the Korea Information Security Agency (KISA) standard - SEED algorithm. |
|
||||||
</body> |
|
||||||
</html> |
|
@ -1,5 +0,0 @@ |
|||||||
<html> |
|
||||||
<body bgcolor="#ffffff"> |
|
||||||
Support for Microsoft specific ASN.1 classes and object identifiers. |
|
||||||
</body> |
|
||||||
</html> |
|
@ -1,5 +0,0 @@ |
|||||||
<html> |
|
||||||
<body bgcolor="#ffffff"> |
|
||||||
Miscellaneous object identifiers and objects. |
|
||||||
</body> |
|
||||||
</html> |
|
@ -1,5 +0,0 @@ |
|||||||
<html> |
|
||||||
<body bgcolor="#ffffff"> |
|
||||||
Support classes useful for encoding objects used by mozilla. |
|
||||||
</body> |
|
||||||
</html> |
|
@ -0,0 +1,114 @@ |
|||||||
|
package com.fr.third.org.bouncycastle.asn1.nist; |
||||||
|
|
||||||
|
import com.fr.third.org.bouncycastle.asn1.ASN1EncodableVector; |
||||||
|
import com.fr.third.org.bouncycastle.asn1.ASN1Integer; |
||||||
|
import com.fr.third.org.bouncycastle.asn1.ASN1Object; |
||||||
|
import com.fr.third.org.bouncycastle.asn1.ASN1OctetString; |
||||||
|
import com.fr.third.org.bouncycastle.asn1.ASN1Primitive; |
||||||
|
import com.fr.third.org.bouncycastle.asn1.ASN1Sequence; |
||||||
|
import com.fr.third.org.bouncycastle.asn1.DEROctetString; |
||||||
|
import com.fr.third.org.bouncycastle.asn1.DERSequence; |
||||||
|
import com.fr.third.org.bouncycastle.util.Arrays; |
||||||
|
|
||||||
|
/** |
||||||
|
* <pre> |
||||||
|
* KMACwithSHAKE128-params ::= SEQUENCE { |
||||||
|
* kMACOutputLength INTEGER DEFAULT 256, -- Output length in bits |
||||||
|
* customizationString OCTET STRING DEFAULT ''H |
||||||
|
* } |
||||||
|
* </pre> |
||||||
|
*/ |
||||||
|
public class KMACwithSHAKE128_params |
||||||
|
extends ASN1Object |
||||||
|
{ |
||||||
|
private static final byte[] EMPTY_STRING = new byte[0]; |
||||||
|
private static final int DEF_LENGTH = 256; |
||||||
|
|
||||||
|
private final int outputLength; |
||||||
|
private final byte[] customizationString; |
||||||
|
|
||||||
|
public KMACwithSHAKE128_params(int outputLength) |
||||||
|
{ |
||||||
|
this.outputLength = outputLength; |
||||||
|
this.customizationString = EMPTY_STRING; |
||||||
|
} |
||||||
|
|
||||||
|
public KMACwithSHAKE128_params(int outputLength, byte[] customizationString) |
||||||
|
{ |
||||||
|
this.outputLength = outputLength; |
||||||
|
this.customizationString = Arrays.clone(customizationString); |
||||||
|
} |
||||||
|
|
||||||
|
public static KMACwithSHAKE128_params getInstance(Object o) |
||||||
|
{ |
||||||
|
if (o instanceof KMACwithSHAKE128_params) |
||||||
|
{ |
||||||
|
return (KMACwithSHAKE128_params)o; |
||||||
|
} |
||||||
|
else if (o != null) |
||||||
|
{ |
||||||
|
return new KMACwithSHAKE128_params(ASN1Sequence.getInstance(o)); |
||||||
|
} |
||||||
|
|
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
private KMACwithSHAKE128_params(ASN1Sequence seq) |
||||||
|
{ |
||||||
|
if (seq.size() > 2) |
||||||
|
{ |
||||||
|
throw new IllegalArgumentException("sequence size greater than 2"); |
||||||
|
} |
||||||
|
|
||||||
|
if (seq.size() == 2) |
||||||
|
{ |
||||||
|
this.outputLength = ASN1Integer.getInstance(seq.getObjectAt(0)).intValueExact(); |
||||||
|
this.customizationString = Arrays.clone(ASN1OctetString.getInstance(seq.getObjectAt(1)).getOctets()); |
||||||
|
} |
||||||
|
else if (seq.size() == 1) |
||||||
|
{ |
||||||
|
if (seq.getObjectAt(0) instanceof ASN1Integer) |
||||||
|
{ |
||||||
|
this.outputLength = ASN1Integer.getInstance(seq.getObjectAt(0)).intValueExact(); |
||||||
|
this.customizationString = EMPTY_STRING; |
||||||
|
} |
||||||
|
else |
||||||
|
{ |
||||||
|
this.outputLength = DEF_LENGTH; |
||||||
|
this.customizationString = Arrays.clone(ASN1OctetString.getInstance(seq.getObjectAt(0)).getOctets()); |
||||||
|
} |
||||||
|
} |
||||||
|
else |
||||||
|
{ |
||||||
|
this.outputLength = DEF_LENGTH; |
||||||
|
this.customizationString = EMPTY_STRING; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public int getOutputLength() |
||||||
|
{ |
||||||
|
return outputLength; |
||||||
|
} |
||||||
|
|
||||||
|
public byte[] getCustomizationString() |
||||||
|
{ |
||||||
|
return Arrays.clone(customizationString); |
||||||
|
} |
||||||
|
|
||||||
|
public ASN1Primitive toASN1Primitive() |
||||||
|
{ |
||||||
|
ASN1EncodableVector v = new ASN1EncodableVector(); |
||||||
|
|
||||||
|
if (outputLength != DEF_LENGTH) |
||||||
|
{ |
||||||
|
v.add(new ASN1Integer(outputLength)); |
||||||
|
} |
||||||
|
|
||||||
|
if (customizationString.length != 0) |
||||||
|
{ |
||||||
|
v.add(new DEROctetString(getCustomizationString())); |
||||||
|
} |
||||||
|
|
||||||
|
return new DERSequence(v); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,114 @@ |
|||||||
|
package com.fr.third.org.bouncycastle.asn1.nist; |
||||||
|
|
||||||
|
import com.fr.third.org.bouncycastle.asn1.ASN1EncodableVector; |
||||||
|
import com.fr.third.org.bouncycastle.asn1.ASN1Integer; |
||||||
|
import com.fr.third.org.bouncycastle.asn1.ASN1Object; |
||||||
|
import com.fr.third.org.bouncycastle.asn1.ASN1OctetString; |
||||||
|
import com.fr.third.org.bouncycastle.asn1.ASN1Primitive; |
||||||
|
import com.fr.third.org.bouncycastle.asn1.ASN1Sequence; |
||||||
|
import com.fr.third.org.bouncycastle.asn1.DEROctetString; |
||||||
|
import com.fr.third.org.bouncycastle.asn1.DERSequence; |
||||||
|
import com.fr.third.org.bouncycastle.util.Arrays; |
||||||
|
|
||||||
|
/** |
||||||
|
* <pre> |
||||||
|
* KMACwithSHAKE256-params ::= SEQUENCE { |
||||||
|
* kMACOutputLength INTEGER DEFAULT 512, -- Output length in bits |
||||||
|
* customizationString OCTET STRING DEFAULT ''H |
||||||
|
* } |
||||||
|
* </pre> |
||||||
|
*/ |
||||||
|
public class KMACwithSHAKE256_params |
||||||
|
extends ASN1Object |
||||||
|
{ |
||||||
|
private static final byte[] EMPTY_STRING = new byte[0]; |
||||||
|
private static final int DEF_LENGTH = 512; |
||||||
|
|
||||||
|
private final int outputLength; |
||||||
|
private final byte[] customizationString; |
||||||
|
|
||||||
|
public KMACwithSHAKE256_params(int outputLength) |
||||||
|
{ |
||||||
|
this.outputLength = outputLength; |
||||||
|
this.customizationString = EMPTY_STRING; |
||||||
|
} |
||||||
|
|
||||||
|
public KMACwithSHAKE256_params(int outputLength, byte[] customizationString) |
||||||
|
{ |
||||||
|
this.outputLength = outputLength; |
||||||
|
this.customizationString = Arrays.clone(customizationString); |
||||||
|
} |
||||||
|
|
||||||
|
public static KMACwithSHAKE256_params getInstance(Object o) |
||||||
|
{ |
||||||
|
if (o instanceof KMACwithSHAKE256_params) |
||||||
|
{ |
||||||
|
return (KMACwithSHAKE256_params)o; |
||||||
|
} |
||||||
|
else if (o != null) |
||||||
|
{ |
||||||
|
return new KMACwithSHAKE256_params(ASN1Sequence.getInstance(o)); |
||||||
|
} |
||||||
|
|
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
private KMACwithSHAKE256_params(ASN1Sequence seq) |
||||||
|
{ |
||||||
|
if (seq.size() > 2) |
||||||
|
{ |
||||||
|
throw new IllegalArgumentException("sequence size greater than 2"); |
||||||
|
} |
||||||
|
|
||||||
|
if (seq.size() == 2) |
||||||
|
{ |
||||||
|
this.outputLength = ASN1Integer.getInstance(seq.getObjectAt(0)).intValueExact(); |
||||||
|
this.customizationString = Arrays.clone(ASN1OctetString.getInstance(seq.getObjectAt(1)).getOctets()); |
||||||
|
} |
||||||
|
else if (seq.size() == 1) |
||||||
|
{ |
||||||
|
if (seq.getObjectAt(0) instanceof ASN1Integer) |
||||||
|
{ |
||||||
|
this.outputLength = ASN1Integer.getInstance(seq.getObjectAt(0)).intValueExact(); |
||||||
|
this.customizationString = EMPTY_STRING; |
||||||
|
} |
||||||
|
else |
||||||
|
{ |
||||||
|
this.outputLength = DEF_LENGTH; |
||||||
|
this.customizationString = Arrays.clone(ASN1OctetString.getInstance(seq.getObjectAt(0)).getOctets()); |
||||||
|
} |
||||||
|
} |
||||||
|
else |
||||||
|
{ |
||||||
|
this.outputLength = DEF_LENGTH; |
||||||
|
this.customizationString = EMPTY_STRING; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public int getOutputLength() |
||||||
|
{ |
||||||
|
return outputLength; |
||||||
|
} |
||||||
|
|
||||||
|
public byte[] getCustomizationString() |
||||||
|
{ |
||||||
|
return Arrays.clone(customizationString); |
||||||
|
} |
||||||
|
|
||||||
|
public ASN1Primitive toASN1Primitive() |
||||||
|
{ |
||||||
|
ASN1EncodableVector v = new ASN1EncodableVector(); |
||||||
|
|
||||||
|
if (outputLength != DEF_LENGTH) |
||||||
|
{ |
||||||
|
v.add(new ASN1Integer(outputLength)); |
||||||
|
} |
||||||
|
|
||||||
|
if (customizationString.length != 0) |
||||||
|
{ |
||||||
|
v.add(new DEROctetString(getCustomizationString())); |
||||||
|
} |
||||||
|
|
||||||
|
return new DERSequence(v); |
||||||
|
} |
||||||
|
} |
@ -1,5 +0,0 @@ |
|||||||
<html> |
|
||||||
<body bgcolor="#ffffff"> |
|
||||||
Support classes for NIST related objects. |
|
||||||
</body> |
|
||||||
</html> |
|
@ -1,5 +0,0 @@ |
|||||||
<html> |
|
||||||
<body bgcolor="#ffffff"> |
|
||||||
Support classes algorithms from the Korean National Security Research Institute. |
|
||||||
</body> |
|
||||||
</html> |
|
@ -1,5 +0,0 @@ |
|||||||
<html> |
|
||||||
<body bgcolor="#ffffff"> |
|
||||||
ASN.1 classes relevant to the standards produced by Nippon Telegraph and Telephone. |
|
||||||
</body> |
|
||||||
</html> |
|
@ -1,5 +0,0 @@ |
|||||||
<html> |
|
||||||
<body bgcolor="#ffffff"> |
|
||||||
Support classes useful for encoding and supporting OCSP objects. |
|
||||||
</body> |
|
||||||
</html> |
|
@ -1,5 +0,0 @@ |
|||||||
<html> |
|
||||||
<body bgcolor="#ffffff"> |
|
||||||
Objects and OID for the support of ISO OIW. |
|
||||||
</body> |
|
||||||
</html> |
|
@ -1,5 +0,0 @@ |
|||||||
<html> |
|
||||||
<body bgcolor="#ffffff"> |
|
||||||
A library for parsing and writing ASN.1 objects. Support is provided for DER and BER encoding. |
|
||||||
</body> |
|
||||||
</html> |
|
@ -1,5 +0,0 @@ |
|||||||
<html> |
|
||||||
<body bgcolor="#ffffff"> |
|
||||||
Support classes useful for encoding and supporting the various RSA PKCS documents. |
|
||||||
</body> |
|
||||||
</html> |
|
@ -1,5 +0,0 @@ |
|||||||
<html> |
|
||||||
<body bgcolor="#ffffff"> |
|
||||||
Support classes algorithms from the Russian Federal Agency on Technical Regulating and Metrology - Rosstandart. |
|
||||||
</body> |
|
||||||
</html> |
|
@ -1,5 +0,0 @@ |
|||||||
<html> |
|
||||||
<body bgcolor="#ffffff"> |
|
||||||
Classes for support of the SEC standard for Elliptic Curve. |
|
||||||
</body> |
|
||||||
</html> |
|
@ -1,5 +0,0 @@ |
|||||||
<html> |
|
||||||
<body bgcolor="#ffffff"> |
|
||||||
Support classes useful for encoding and supporting S/MIME. |
|
||||||
</body> |
|
||||||
</html> |
|
@ -1,5 +0,0 @@ |
|||||||
<html> |
|
||||||
<body bgcolor="#ffffff"> |
|
||||||
Support classes for TeleTrust related objects. |
|
||||||
</body> |
|
||||||
</html> |
|
@ -1,365 +0,0 @@ |
|||||||
package com.fr.third.org.bouncycastle.asn1.test; |
|
||||||
|
|
||||||
import java.math.BigInteger; |
|
||||||
|
|
||||||
import com.fr.third.org.bouncycastle.asn1.ASN1Enumerated; |
|
||||||
import com.fr.third.org.bouncycastle.asn1.ASN1Integer; |
|
||||||
import com.fr.third.org.bouncycastle.asn1.ASN1Sequence; |
|
||||||
import com.fr.third.org.bouncycastle.util.BigIntegers; |
|
||||||
import com.fr.third.org.bouncycastle.util.Properties; |
|
||||||
import com.fr.third.org.bouncycastle.util.encoders.Base64; |
|
||||||
import com.fr.third.org.bouncycastle.util.encoders.Hex; |
|
||||||
import com.fr.third.org.bouncycastle.util.test.SimpleTest; |
|
||||||
|
|
||||||
public class ASN1IntegerTest |
|
||||||
extends SimpleTest |
|
||||||
{ |
|
||||||
private static final byte[] suspectKey = Base64.decode( |
|
||||||
"MIGJAoGBAHNc+iExm94LUrJdPSJ4QJ9tDRuvaNmGVHpJ4X7a5zKI02v+2E7RotuiR2MHDJfVJkb9LUs2kb3XBlyENhtMLsbeH+3Muy3" + |
|
||||||
"hGDlh/mLJSh1s4c5jDKBRYOHom7Uc8wP0P2+zBCA+OEdikNDFBaP5PbR2Xq9okG2kPh35M2quAiMTAgMBAAE="); |
|
||||||
|
|
||||||
public String getName() |
|
||||||
{ |
|
||||||
return "ASN1Integer"; |
|
||||||
} |
|
||||||
|
|
||||||
public void performTest() |
|
||||||
throws Exception |
|
||||||
{ |
|
||||||
System.setProperty("com.fr.third.org.bouncycastle.asn1.allow_unsafe_integer", "true"); |
|
||||||
|
|
||||||
ASN1Sequence.getInstance(suspectKey); |
|
||||||
|
|
||||||
testValidEncodingSingleByte(); |
|
||||||
testValidEncodingMultiByte(); |
|
||||||
testInvalidEncoding_00(); |
|
||||||
testInvalidEncoding_ff(); |
|
||||||
testInvalidEncoding_00_32bits(); |
|
||||||
testInvalidEncoding_ff_32bits(); |
|
||||||
//testLooseInvalidValidEncoding_FF_32B();
|
|
||||||
//testLooseInvalidValidEncoding_zero_32B();
|
|
||||||
testLooseValidEncoding_zero_32BAligned(); |
|
||||||
testLooseValidEncoding_FF_32BAligned(); |
|
||||||
testLooseValidEncoding_FF_32BAligned_1not0(); |
|
||||||
testLooseValidEncoding_FF_32BAligned_2not0(); |
|
||||||
testOversizedEncoding(); |
|
||||||
|
|
||||||
System.setProperty("com.fr.third.org.bouncycastle.asn1.allow_unsafe_integer", "true"); |
|
||||||
|
|
||||||
new ASN1Integer(Hex.decode("ffda47bfc776bcd269da4832626ac332adfca6dd835e8ecd83cd1ebe7d709b0e")); |
|
||||||
|
|
||||||
new ASN1Enumerated(Hex.decode("005a47bfc776bcd269da4832626ac332adfca6dd835e8ecd83cd1ebe7d709b0e")); |
|
||||||
|
|
||||||
System.setProperty("com.fr.third.org.bouncycastle.asn1.allow_unsafe_integer", "false"); |
|
||||||
|
|
||||||
try |
|
||||||
{ |
|
||||||
new ASN1Integer(Hex.decode("ffda47bfc776bcd269da4832626ac332adfca6dd835e8ecd83cd1ebe7d709b")); |
|
||||||
|
|
||||||
fail("no exception"); |
|
||||||
} |
|
||||||
catch (IllegalArgumentException e) |
|
||||||
{ |
|
||||||
isEquals("malformed integer", e.getMessage()); |
|
||||||
} |
|
||||||
|
|
||||||
isTrue(!Properties.setThreadOverride("com.fr.third.org.bouncycastle.asn1.allow_unsafe_integer", true)); |
|
||||||
|
|
||||||
new ASN1Integer(Hex.decode("ffda47bfc776bcd269da4832626ac332adfca6dd835e8ecd83cd1ebe7d709b")); |
|
||||||
|
|
||||||
isTrue(Properties.removeThreadOverride("com.fr.third.org.bouncycastle.asn1.allow_unsafe_integer")); |
|
||||||
|
|
||||||
try |
|
||||||
{ |
|
||||||
ASN1Sequence.getInstance(suspectKey); |
|
||||||
|
|
||||||
fail("no exception"); |
|
||||||
} |
|
||||||
catch (IllegalArgumentException e) |
|
||||||
{ |
|
||||||
isEquals("test 1", "failed to construct sequence from byte[]: corrupted stream detected", e.getMessage()); |
|
||||||
} |
|
||||||
|
|
||||||
try |
|
||||||
{ |
|
||||||
new ASN1Integer(Hex.decode("ffda47bfc776bcd269da4832626ac332adfca6dd835e8ecd83cd1ebe7d709b0e")); |
|
||||||
|
|
||||||
fail("no exception"); |
|
||||||
} |
|
||||||
catch (IllegalArgumentException e) |
|
||||||
{ |
|
||||||
isEquals("malformed integer", e.getMessage()); |
|
||||||
} |
|
||||||
|
|
||||||
try |
|
||||||
{ |
|
||||||
new ASN1Enumerated(Hex.decode("ffda47bfc776bcd269da4832626ac332adfca6dd835e8ecd83cd1ebe7d709b0e")); |
|
||||||
|
|
||||||
fail("no exception"); |
|
||||||
} |
|
||||||
catch (IllegalArgumentException e) |
|
||||||
{ |
|
||||||
isEquals("malformed enumerated", e.getMessage()); |
|
||||||
} |
|
||||||
|
|
||||||
try |
|
||||||
{ |
|
||||||
new ASN1Enumerated(Hex.decode("005a47bfc776bcd269da4832626ac332adfca6dd835e8ecd83cd1ebe7d709b0e")); |
|
||||||
|
|
||||||
fail("no exception"); |
|
||||||
} |
|
||||||
catch (IllegalArgumentException e) |
|
||||||
{ |
|
||||||
isEquals("malformed enumerated", e.getMessage()); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Ensure existing single byte behavior. |
|
||||||
*/ |
|
||||||
public void testValidEncodingSingleByte() |
|
||||||
throws Exception |
|
||||||
{ |
|
||||||
System.setProperty("com.fr.third.org.bouncycastle.asn1.allow_unsafe_integer", "false"); |
|
||||||
//
|
|
||||||
// Without property, single byte.
|
|
||||||
//
|
|
||||||
byte[] rawInt = Hex.decode("10"); |
|
||||||
ASN1Integer i = new ASN1Integer(rawInt); |
|
||||||
isEquals(i.getValue().intValue(), 16); |
|
||||||
isEquals(i.intValueExact(), 16); |
|
||||||
|
|
||||||
//
|
|
||||||
// With property set.
|
|
||||||
//
|
|
||||||
System.setProperty("com.fr.third.org.bouncycastle.asn1.allow_unsafe_integer", "true"); |
|
||||||
|
|
||||||
rawInt = Hex.decode("10"); |
|
||||||
i = new ASN1Integer(rawInt); |
|
||||||
isEquals(i.getValue().intValue(), 16); |
|
||||||
isEquals(i.intValueExact(), 16); |
|
||||||
} |
|
||||||
|
|
||||||
public void testValidEncodingMultiByte() |
|
||||||
throws Exception |
|
||||||
{ |
|
||||||
System.setProperty("com.fr.third.org.bouncycastle.asn1.allow_unsafe_integer", "false"); |
|
||||||
//
|
|
||||||
// Without property, single byte.
|
|
||||||
//
|
|
||||||
byte[] rawInt = Hex.decode("10FF"); |
|
||||||
ASN1Integer i = new ASN1Integer(rawInt); |
|
||||||
isEquals(i.getValue().intValue(), 4351); |
|
||||||
isEquals(i.intValueExact(), 4351); |
|
||||||
|
|
||||||
//
|
|
||||||
// With property set.
|
|
||||||
//
|
|
||||||
System.setProperty("com.fr.third.org.bouncycastle.asn1.allow_unsafe_integer", "true"); |
|
||||||
|
|
||||||
rawInt = Hex.decode("10FF"); |
|
||||||
i = new ASN1Integer(rawInt); |
|
||||||
isEquals(i.getValue().intValue(), 4351); |
|
||||||
isEquals(i.intValueExact(), 4351); |
|
||||||
} |
|
||||||
|
|
||||||
public void testInvalidEncoding_00() |
|
||||||
throws Exception |
|
||||||
{ |
|
||||||
System.setProperty("com.fr.third.org.bouncycastle.asn1.allow_unsafe_integer", "false"); |
|
||||||
try |
|
||||||
{ |
|
||||||
byte[] rawInt = Hex.decode("0010FF"); |
|
||||||
new ASN1Integer(rawInt); |
|
||||||
fail("Expecting illegal argument exception."); |
|
||||||
} |
|
||||||
catch (IllegalArgumentException e) |
|
||||||
{ |
|
||||||
isEquals("malformed integer", e.getMessage()); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public void testInvalidEncoding_ff() |
|
||||||
throws Exception |
|
||||||
{ |
|
||||||
System.setProperty("com.fr.third.org.bouncycastle.asn1.allow_unsafe_integer", "false"); |
|
||||||
try |
|
||||||
{ |
|
||||||
byte[] rawInt = Hex.decode("FF81FF"); |
|
||||||
new ASN1Integer(rawInt); |
|
||||||
fail("Expecting illegal argument exception."); |
|
||||||
} |
|
||||||
catch (IllegalArgumentException e) |
|
||||||
{ |
|
||||||
isEquals("malformed integer", e.getMessage()); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public void testInvalidEncoding_00_32bits() |
|
||||||
throws Exception |
|
||||||
{ |
|
||||||
System.setProperty("com.fr.third.org.bouncycastle.asn1.allow_unsafe_integer", "false"); |
|
||||||
//
|
|
||||||
// Check what would pass loose validation fails outside of loose validation.
|
|
||||||
//
|
|
||||||
try |
|
||||||
{ |
|
||||||
byte[] rawInt = Hex.decode("0000000010FF"); |
|
||||||
new ASN1Integer(rawInt); |
|
||||||
fail("Expecting illegal argument exception."); |
|
||||||
} |
|
||||||
catch (IllegalArgumentException e) |
|
||||||
{ |
|
||||||
isEquals("malformed integer", e.getMessage()); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public void testInvalidEncoding_ff_32bits() |
|
||||||
throws Exception |
|
||||||
{ |
|
||||||
System.setProperty("com.fr.third.org.bouncycastle.asn1.allow_unsafe_integer", "false"); |
|
||||||
//
|
|
||||||
// Check what would pass loose validation fails outside of loose validation.
|
|
||||||
//
|
|
||||||
try |
|
||||||
{ |
|
||||||
byte[] rawInt = Hex.decode("FFFFFFFF01FF"); |
|
||||||
new ASN1Integer(rawInt); |
|
||||||
fail("Expecting illegal argument exception."); |
|
||||||
} |
|
||||||
catch (IllegalArgumentException e) |
|
||||||
{ |
|
||||||
isEquals("malformed integer", e.getMessage()); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/* |
|
||||||
Unfortunately it turns out that integers stored without sign bits that are assumed to be |
|
||||||
unsigned.. this means a string of FF may occur and then the user will call getPositiveValue(). |
|
||||||
Sigh.. |
|
||||||
public void testLooseInvalidValidEncoding_zero_32B() |
|
||||||
throws Exception |
|
||||||
{ |
|
||||||
System.setProperty("com.fr.third.org.bouncycastle.asn1.allow_unsafe_integer", "false"); |
|
||||||
//
|
|
||||||
// Should still fail as loose validation only permits 3 leading 0x00 bytes.
|
|
||||||
//
|
|
||||||
try |
|
||||||
{ |
|
||||||
System.getProperties().put("com.fr.third.org.bouncycastle.asn1.allow_unsafe_integer", "true"); |
|
||||||
byte[] rawInt = Hex.decode("0000000010FF"); |
|
||||||
ASN1Integer i = new ASN1Integer(rawInt); |
|
||||||
fail("Expecting illegal argument exception."); |
|
||||||
} |
|
||||||
catch (IllegalArgumentException e) |
|
||||||
{ |
|
||||||
isEquals("malformed integer", e.getMessage()); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public void testLooseInvalidValidEncoding_FF_32B() |
|
||||||
throws Exception |
|
||||||
{ |
|
||||||
System.setProperty("com.fr.third.org.bouncycastle.asn1.allow_unsafe_integer", "false"); |
|
||||||
//
|
|
||||||
// Should still fail as loose validation only permits 3 leading 0xFF bytes.
|
|
||||||
//
|
|
||||||
try |
|
||||||
{ |
|
||||||
System.getProperties().put("com.fr.third.org.bouncycastle.asn1.allow_unsafe_integer", "true"); |
|
||||||
byte[] rawInt = Hex.decode("FFFFFFFF10FF"); |
|
||||||
ASN1Integer i = new ASN1Integer(rawInt); |
|
||||||
fail("Expecting illegal argument exception."); |
|
||||||
} |
|
||||||
catch (IllegalArgumentException e) |
|
||||||
{ |
|
||||||
isEquals("malformed integer", e.getMessage()); |
|
||||||
} |
|
||||||
} |
|
||||||
*/ |
|
||||||
|
|
||||||
public void testLooseValidEncoding_zero_32BAligned() |
|
||||||
throws Exception |
|
||||||
{ |
|
||||||
System.setProperty("com.fr.third.org.bouncycastle.asn1.allow_unsafe_integer", "false"); |
|
||||||
//
|
|
||||||
// Should pass as loose validation permits 3 leading 0x00 bytes.
|
|
||||||
//
|
|
||||||
|
|
||||||
System.getProperties().put("com.fr.third.org.bouncycastle.asn1.allow_unsafe_integer", "true"); |
|
||||||
byte[] rawInt = Hex.decode("00000010FF000000"); |
|
||||||
ASN1Integer i = new ASN1Integer(rawInt); |
|
||||||
isEquals(72997666816L, BigIntegers.longValueExact(i.getValue())); |
|
||||||
} |
|
||||||
|
|
||||||
public void testLooseValidEncoding_FF_32BAligned() |
|
||||||
throws Exception |
|
||||||
{ |
|
||||||
System.setProperty("com.fr.third.org.bouncycastle.asn1.allow_unsafe_integer", "false"); |
|
||||||
//
|
|
||||||
// Should pass as loose validation permits 3
|
|
||||||
|
|
||||||
System.getProperties().put("com.fr.third.org.bouncycastle.asn1.allow_unsafe_integer", "true"); |
|
||||||
byte[] rawInt = Hex.decode("FFFFFF10FF000000"); |
|
||||||
ASN1Integer i = new ASN1Integer(rawInt); |
|
||||||
isEquals(-1026513960960L, BigIntegers.longValueExact(i.getValue())); |
|
||||||
} |
|
||||||
|
|
||||||
public void testLooseValidEncoding_FF_32BAligned_1not0() |
|
||||||
throws Exception |
|
||||||
{ |
|
||||||
System.setProperty("com.fr.third.org.bouncycastle.asn1.allow_unsafe_integer", "false"); |
|
||||||
//
|
|
||||||
// Should pass as loose validation permits 3 leading 0xFF bytes.
|
|
||||||
//
|
|
||||||
|
|
||||||
System.getProperties().put("com.fr.third.org.bouncycastle.asn1.allow_unsafe_integer", "true"); |
|
||||||
byte[] rawInt = Hex.decode("FFFEFF10FF000000"); |
|
||||||
ASN1Integer i = new ASN1Integer(rawInt); |
|
||||||
isEquals(-282501490671616L, BigIntegers.longValueExact(i.getValue())); |
|
||||||
} |
|
||||||
|
|
||||||
public void testLooseValidEncoding_FF_32BAligned_2not0() |
|
||||||
throws Exception |
|
||||||
{ |
|
||||||
System.setProperty("com.fr.third.org.bouncycastle.asn1.allow_unsafe_integer", "false"); |
|
||||||
//
|
|
||||||
// Should pass as loose validation permits 3 leading 0xFF bytes.
|
|
||||||
//
|
|
||||||
|
|
||||||
System.getProperties().put("com.fr.third.org.bouncycastle.asn1.allow_unsafe_integer", "true"); |
|
||||||
byte[] rawInt = Hex.decode("FFFFFE10FF000000"); |
|
||||||
ASN1Integer i = new ASN1Integer(rawInt); |
|
||||||
isEquals(-2126025588736L, BigIntegers.longValueExact(i.getValue())); |
|
||||||
} |
|
||||||
|
|
||||||
public void testOversizedEncoding() |
|
||||||
throws Exception |
|
||||||
{ |
|
||||||
System.setProperty("com.fr.third.org.bouncycastle.asn1.allow_unsafe_integer", "false"); |
|
||||||
//
|
|
||||||
// Should pass as loose validation permits 3 leading 0xFF bytes.
|
|
||||||
//
|
|
||||||
|
|
||||||
System.getProperties().put("com.fr.third.org.bouncycastle.asn1.allow_unsafe_integer", "true"); |
|
||||||
byte[] rawInt = Hex.decode("FFFFFFFE10FF000000000000"); |
|
||||||
ASN1Integer i = new ASN1Integer(rawInt); |
|
||||||
isEquals(new BigInteger(Hex.decode("FFFFFFFE10FF000000000000")), i.getValue()); |
|
||||||
|
|
||||||
rawInt = Hex.decode("FFFFFFFFFE10FF000000000000"); |
|
||||||
try |
|
||||||
{ |
|
||||||
new ASN1Integer(rawInt); |
|
||||||
} |
|
||||||
catch (IllegalArgumentException e) |
|
||||||
{ |
|
||||||
isEquals("malformed integer", e.getMessage()); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public static void main( |
|
||||||
String[] args) |
|
||||||
{ |
|
||||||
runTest(new ASN1IntegerTest()); |
|
||||||
} |
|
||||||
} |
|
@ -1,89 +0,0 @@ |
|||||||
package com.fr.third.org.bouncycastle.asn1.test; |
|
||||||
|
|
||||||
import com.fr.third.org.bouncycastle.asn1.ASN1Encodable; |
|
||||||
import com.fr.third.org.bouncycastle.util.test.SimpleTest; |
|
||||||
|
|
||||||
import java.math.BigInteger; |
|
||||||
|
|
||||||
public abstract class ASN1UnitTest |
|
||||||
extends SimpleTest |
|
||||||
{ |
|
||||||
protected void checkMandatoryField(String name, ASN1Encodable expected, ASN1Encodable present) |
|
||||||
{ |
|
||||||
if (!expected.equals(present)) |
|
||||||
{ |
|
||||||
fail(name + " field doesn't match."); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
protected void checkMandatoryField(String name, String expected, String present) |
|
||||||
{ |
|
||||||
if (!expected.equals(present)) |
|
||||||
{ |
|
||||||
fail(name + " field doesn't match."); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
protected void checkMandatoryField(String name, byte[] expected, byte[] present) |
|
||||||
{ |
|
||||||
if (!areEqual(expected, present)) |
|
||||||
{ |
|
||||||
fail(name + " field doesn't match."); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
protected void checkMandatoryField(String name, int expected, int present) |
|
||||||
{ |
|
||||||
if (expected != present) |
|
||||||
{ |
|
||||||
fail(name + " field doesn't match."); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
protected void checkOptionalField(String name, ASN1Encodable expected, ASN1Encodable present) |
|
||||||
{ |
|
||||||
if (expected != null) |
|
||||||
{ |
|
||||||
if (!expected.equals(present)) |
|
||||||
{ |
|
||||||
fail(name + " field doesn't match."); |
|
||||||
} |
|
||||||
} |
|
||||||
else if (present != null) |
|
||||||
{ |
|
||||||
fail(name + " field found when none expected."); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
protected void checkOptionalField(String name, String expected, String present) |
|
||||||
{ |
|
||||||
if (expected != null) |
|
||||||
{ |
|
||||||
if (!expected.equals(present)) |
|
||||||
{ |
|
||||||
fail(name + " field doesn't match."); |
|
||||||
} |
|
||||||
} |
|
||||||
else if (present != null) |
|
||||||
{ |
|
||||||
fail(name + " field found when none expected."); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
protected void checkOptionalField(String name, BigInteger expected, BigInteger present) |
|
||||||
{ |
|
||||||
if (expected != null) |
|
||||||
{ |
|
||||||
if (!expected.equals(present)) |
|
||||||
{ |
|
||||||
fail(name + " field doesn't match."); |
|
||||||
} |
|
||||||
} |
|
||||||
else if (present != null) |
|
||||||
{ |
|
||||||
fail(name + " field found when none expected."); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
} |
|
@ -1,69 +0,0 @@ |
|||||||
package com.fr.third.org.bouncycastle.asn1.test; |
|
||||||
|
|
||||||
import java.io.IOException; |
|
||||||
|
|
||||||
import com.fr.third.org.bouncycastle.asn1.ASN1InputStream; |
|
||||||
import com.fr.third.org.bouncycastle.asn1.ASN1String; |
|
||||||
import com.fr.third.org.bouncycastle.asn1.isismtt.x509.AdditionalInformationSyntax; |
|
||||||
import com.fr.third.org.bouncycastle.asn1.x500.DirectoryString; |
|
||||||
|
|
||||||
public class AdditionalInformationSyntaxUnitTest |
|
||||||
extends ASN1UnitTest |
|
||||||
{ |
|
||||||
public String getName() |
|
||||||
{ |
|
||||||
return "AdditionalInformationSyntax"; |
|
||||||
} |
|
||||||
|
|
||||||
public void performTest() |
|
||||||
throws Exception |
|
||||||
{ |
|
||||||
AdditionalInformationSyntax syntax = new AdditionalInformationSyntax("hello world"); |
|
||||||
|
|
||||||
checkConstruction(syntax, new DirectoryString("hello world")); |
|
||||||
|
|
||||||
try |
|
||||||
{ |
|
||||||
AdditionalInformationSyntax.getInstance(new Object()); |
|
||||||
|
|
||||||
fail("getInstance() failed to detect bad object."); |
|
||||||
} |
|
||||||
catch (IllegalArgumentException e) |
|
||||||
{ |
|
||||||
// expected
|
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private void checkConstruction( |
|
||||||
AdditionalInformationSyntax syntax, |
|
||||||
DirectoryString information) |
|
||||||
throws IOException |
|
||||||
{ |
|
||||||
checkValues(syntax, information); |
|
||||||
|
|
||||||
syntax = AdditionalInformationSyntax.getInstance(syntax); |
|
||||||
|
|
||||||
checkValues(syntax, information); |
|
||||||
|
|
||||||
ASN1InputStream aIn = new ASN1InputStream(syntax.toASN1Primitive().getEncoded()); |
|
||||||
|
|
||||||
ASN1String info = (ASN1String)aIn.readObject(); |
|
||||||
|
|
||||||
syntax = AdditionalInformationSyntax.getInstance(info); |
|
||||||
|
|
||||||
checkValues(syntax, information); |
|
||||||
} |
|
||||||
|
|
||||||
private void checkValues( |
|
||||||
AdditionalInformationSyntax syntax, |
|
||||||
DirectoryString information) |
|
||||||
{ |
|
||||||
checkMandatoryField("information", information, syntax.getInformation()); |
|
||||||
} |
|
||||||
|
|
||||||
public static void main( |
|
||||||
String[] args) |
|
||||||
{ |
|
||||||
runTest(new AdditionalInformationSyntaxUnitTest()); |
|
||||||
} |
|
||||||
} |
|
@ -1,97 +0,0 @@ |
|||||||
package com.fr.third.org.bouncycastle.asn1.test; |
|
||||||
|
|
||||||
import java.io.IOException; |
|
||||||
|
|
||||||
import com.fr.third.org.bouncycastle.asn1.ASN1InputStream; |
|
||||||
import com.fr.third.org.bouncycastle.asn1.ASN1ObjectIdentifier; |
|
||||||
import com.fr.third.org.bouncycastle.asn1.ASN1Sequence; |
|
||||||
import com.fr.third.org.bouncycastle.asn1.DERSequence; |
|
||||||
import com.fr.third.org.bouncycastle.asn1.isismtt.x509.AdmissionSyntax; |
|
||||||
import com.fr.third.org.bouncycastle.asn1.isismtt.x509.Admissions; |
|
||||||
import com.fr.third.org.bouncycastle.asn1.isismtt.x509.NamingAuthority; |
|
||||||
import com.fr.third.org.bouncycastle.asn1.isismtt.x509.ProfessionInfo; |
|
||||||
import com.fr.third.org.bouncycastle.asn1.x500.DirectoryString; |
|
||||||
import com.fr.third.org.bouncycastle.asn1.x500.X500Name; |
|
||||||
import com.fr.third.org.bouncycastle.asn1.x509.GeneralName; |
|
||||||
|
|
||||||
public class AdmissionSyntaxUnitTest |
|
||||||
extends ASN1UnitTest |
|
||||||
{ |
|
||||||
public String getName() |
|
||||||
{ |
|
||||||
return "AdmissionSyntax"; |
|
||||||
} |
|
||||||
|
|
||||||
public void performTest() |
|
||||||
throws Exception |
|
||||||
{ |
|
||||||
GeneralName name = new GeneralName(new X500Name("CN=hello world")); |
|
||||||
ASN1Sequence admissions = new DERSequence( |
|
||||||
new Admissions(name, |
|
||||||
new NamingAuthority(new ASN1ObjectIdentifier("1.2.3"), "url", new DirectoryString("fred")), |
|
||||||
new ProfessionInfo[0])); |
|
||||||
AdmissionSyntax syntax = new AdmissionSyntax(name, admissions); |
|
||||||
|
|
||||||
checkConstruction(syntax, name, admissions); |
|
||||||
|
|
||||||
syntax = AdmissionSyntax.getInstance(null); |
|
||||||
|
|
||||||
if (syntax != null) |
|
||||||
{ |
|
||||||
fail("null getInstance() failed."); |
|
||||||
} |
|
||||||
|
|
||||||
try |
|
||||||
{ |
|
||||||
AdmissionSyntax.getInstance(new Object()); |
|
||||||
|
|
||||||
fail("getInstance() failed to detect bad object."); |
|
||||||
} |
|
||||||
catch (IllegalArgumentException e) |
|
||||||
{ |
|
||||||
// expected
|
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private void checkConstruction( |
|
||||||
AdmissionSyntax syntax, |
|
||||||
GeneralName authority, |
|
||||||
ASN1Sequence admissions) |
|
||||||
throws IOException |
|
||||||
{ |
|
||||||
checkValues(syntax, authority, admissions); |
|
||||||
|
|
||||||
syntax = AdmissionSyntax.getInstance(syntax); |
|
||||||
|
|
||||||
checkValues(syntax, authority, admissions); |
|
||||||
|
|
||||||
ASN1InputStream aIn = new ASN1InputStream(syntax.toASN1Primitive().getEncoded()); |
|
||||||
|
|
||||||
ASN1Sequence info = (ASN1Sequence)aIn.readObject(); |
|
||||||
|
|
||||||
syntax = AdmissionSyntax.getInstance(info); |
|
||||||
|
|
||||||
checkValues(syntax, authority, admissions); |
|
||||||
} |
|
||||||
|
|
||||||
private void checkValues( |
|
||||||
AdmissionSyntax syntax, |
|
||||||
GeneralName authority, |
|
||||||
ASN1Sequence admissions) |
|
||||||
{ |
|
||||||
checkMandatoryField("admissionAuthority", authority, syntax.getAdmissionAuthority()); |
|
||||||
|
|
||||||
Admissions[] adm = syntax.getContentsOfAdmissions(); |
|
||||||
|
|
||||||
if (adm.length != 1 || !adm[0].equals(admissions.getObjectAt(0))) |
|
||||||
{ |
|
||||||
fail("admissions check failed"); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public static void main( |
|
||||||
String[] args) |
|
||||||
{ |
|
||||||
runTest(new AdmissionSyntaxUnitTest()); |
|
||||||
} |
|
||||||
} |
|
@ -1,86 +0,0 @@ |
|||||||
package com.fr.third.org.bouncycastle.asn1.test; |
|
||||||
|
|
||||||
import java.io.IOException; |
|
||||||
|
|
||||||
import com.fr.third.org.bouncycastle.asn1.ASN1InputStream; |
|
||||||
import com.fr.third.org.bouncycastle.asn1.ASN1ObjectIdentifier; |
|
||||||
import com.fr.third.org.bouncycastle.asn1.ASN1Sequence; |
|
||||||
import com.fr.third.org.bouncycastle.asn1.isismtt.x509.Admissions; |
|
||||||
import com.fr.third.org.bouncycastle.asn1.isismtt.x509.NamingAuthority; |
|
||||||
import com.fr.third.org.bouncycastle.asn1.isismtt.x509.ProfessionInfo; |
|
||||||
import com.fr.third.org.bouncycastle.asn1.x500.DirectoryString; |
|
||||||
import com.fr.third.org.bouncycastle.asn1.x500.X500Name; |
|
||||||
import com.fr.third.org.bouncycastle.asn1.x509.GeneralName; |
|
||||||
|
|
||||||
public class AdmissionsUnitTest |
|
||||||
extends ASN1UnitTest |
|
||||||
{ |
|
||||||
public String getName() |
|
||||||
{ |
|
||||||
return "Admissions"; |
|
||||||
} |
|
||||||
|
|
||||||
public void performTest() |
|
||||||
throws Exception |
|
||||||
{ |
|
||||||
GeneralName name = new GeneralName(new X500Name("CN=hello world")); |
|
||||||
NamingAuthority auth = new NamingAuthority(new ASN1ObjectIdentifier("1.2.3"), "url", new DirectoryString("fred")); |
|
||||||
Admissions admissions = new Admissions(name, auth, new ProfessionInfo[0]); |
|
||||||
|
|
||||||
checkConstruction(admissions, name, auth); |
|
||||||
|
|
||||||
admissions = Admissions.getInstance(null); |
|
||||||
|
|
||||||
if (admissions != null) |
|
||||||
{ |
|
||||||
fail("null getInstance() failed."); |
|
||||||
} |
|
||||||
|
|
||||||
try |
|
||||||
{ |
|
||||||
Admissions.getInstance(new Object()); |
|
||||||
|
|
||||||
fail("getInstance() failed to detect bad object."); |
|
||||||
} |
|
||||||
catch (IllegalArgumentException e) |
|
||||||
{ |
|
||||||
// expected
|
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private void checkConstruction( |
|
||||||
Admissions admissions, |
|
||||||
GeneralName name, |
|
||||||
NamingAuthority auth) |
|
||||||
throws IOException |
|
||||||
{ |
|
||||||
checkValues(admissions, name, auth); |
|
||||||
|
|
||||||
admissions = Admissions.getInstance(admissions); |
|
||||||
|
|
||||||
checkValues(admissions, name, auth); |
|
||||||
|
|
||||||
ASN1InputStream aIn = new ASN1InputStream(admissions.toASN1Primitive().getEncoded()); |
|
||||||
|
|
||||||
ASN1Sequence info = (ASN1Sequence)aIn.readObject(); |
|
||||||
|
|
||||||
admissions = Admissions.getInstance(info); |
|
||||||
|
|
||||||
checkValues(admissions, name, auth); |
|
||||||
} |
|
||||||
|
|
||||||
private void checkValues( |
|
||||||
Admissions admissions, |
|
||||||
GeneralName name, |
|
||||||
NamingAuthority auth) |
|
||||||
{ |
|
||||||
checkMandatoryField("admissionAuthority", name, admissions.getAdmissionAuthority()); |
|
||||||
checkMandatoryField("namingAuthority", auth, admissions.getNamingAuthority()); |
|
||||||
} |
|
||||||
|
|
||||||
public static void main( |
|
||||||
String[] args) |
|
||||||
{ |
|
||||||
runTest(new AdmissionsUnitTest()); |
|
||||||
} |
|
||||||
} |
|
@ -1,144 +0,0 @@ |
|||||||
package com.fr.third.org.bouncycastle.asn1.test; |
|
||||||
|
|
||||||
import java.util.Hashtable; |
|
||||||
|
|
||||||
import com.fr.third.org.bouncycastle.asn1.ASN1EncodableVector; |
|
||||||
import com.fr.third.org.bouncycastle.asn1.ASN1ObjectIdentifier; |
|
||||||
import com.fr.third.org.bouncycastle.asn1.DERSet; |
|
||||||
import com.fr.third.org.bouncycastle.asn1.cms.Attribute; |
|
||||||
import com.fr.third.org.bouncycastle.asn1.cms.AttributeTable; |
|
||||||
import com.fr.third.org.bouncycastle.util.test.SimpleTest; |
|
||||||
|
|
||||||
public class AttributeTableUnitTest |
|
||||||
extends SimpleTest |
|
||||||
{ |
|
||||||
private static final ASN1ObjectIdentifier type1 = new ASN1ObjectIdentifier("1.1.1"); |
|
||||||
private static final ASN1ObjectIdentifier type2 = new ASN1ObjectIdentifier("1.1.2"); |
|
||||||
private static final ASN1ObjectIdentifier type3 = new ASN1ObjectIdentifier("1.1.3"); |
|
||||||
|
|
||||||
public String getName() |
|
||||||
{ |
|
||||||
return "AttributeTable"; |
|
||||||
} |
|
||||||
|
|
||||||
public void performTest() |
|
||||||
throws Exception |
|
||||||
{ |
|
||||||
ASN1EncodableVector v = new ASN1EncodableVector(); |
|
||||||
|
|
||||||
v.add(new Attribute(type1, new DERSet(type1))); |
|
||||||
v.add(new Attribute(type2, new DERSet(type2))); |
|
||||||
|
|
||||||
AttributeTable table = new AttributeTable(v); |
|
||||||
|
|
||||||
Attribute a = table.get(type1); |
|
||||||
if (a == null) |
|
||||||
{ |
|
||||||
fail("type1 attribute not found."); |
|
||||||
} |
|
||||||
if (!a.getAttrValues().equals(new DERSet(type1))) |
|
||||||
{ |
|
||||||
fail("wrong value retrieved for type1!"); |
|
||||||
} |
|
||||||
|
|
||||||
a = table.get(type2); |
|
||||||
if (a == null) |
|
||||||
{ |
|
||||||
fail("type2 attribute not found."); |
|
||||||
} |
|
||||||
if (!a.getAttrValues().equals(new DERSet(type2))) |
|
||||||
{ |
|
||||||
fail("wrong value retrieved for type2!"); |
|
||||||
} |
|
||||||
|
|
||||||
a = table.get(type3); |
|
||||||
if (a != null) |
|
||||||
{ |
|
||||||
fail("type3 attribute found when none expected."); |
|
||||||
} |
|
||||||
|
|
||||||
ASN1EncodableVector vec = table.getAll(type1); |
|
||||||
if (vec.size() != 1) |
|
||||||
{ |
|
||||||
fail("wrong vector size for type1."); |
|
||||||
} |
|
||||||
|
|
||||||
vec = table.getAll(type3); |
|
||||||
if (vec.size() != 0) |
|
||||||
{ |
|
||||||
fail("wrong vector size for type3."); |
|
||||||
} |
|
||||||
|
|
||||||
vec = table.toASN1EncodableVector(); |
|
||||||
if (vec.size() != 2) |
|
||||||
{ |
|
||||||
fail("wrong vector size for single."); |
|
||||||
} |
|
||||||
|
|
||||||
Hashtable t = table.toHashtable(); |
|
||||||
|
|
||||||
if (t.size() != 2) |
|
||||||
{ |
|
||||||
fail("hashtable wrong size."); |
|
||||||
} |
|
||||||
|
|
||||||
// multiple
|
|
||||||
|
|
||||||
v = new ASN1EncodableVector(); |
|
||||||
|
|
||||||
v.add(new Attribute(type1, new DERSet(type1))); |
|
||||||
v.add(new Attribute(type1, new DERSet(type2))); |
|
||||||
v.add(new Attribute(type1, new DERSet(type3))); |
|
||||||
v.add(new Attribute(type2, new DERSet(type2))); |
|
||||||
|
|
||||||
table = new AttributeTable(v); |
|
||||||
|
|
||||||
a = table.get(type1); |
|
||||||
if (!a.getAttrValues().equals(new DERSet(type1))) |
|
||||||
{ |
|
||||||
fail("wrong value retrieved for type1 multi get!"); |
|
||||||
} |
|
||||||
|
|
||||||
vec = table.getAll(type1); |
|
||||||
if (vec.size() != 3) |
|
||||||
{ |
|
||||||
fail("wrong vector size for multiple type1."); |
|
||||||
} |
|
||||||
|
|
||||||
a = (Attribute)vec.get(0); |
|
||||||
if (!a.getAttrValues().equals(new DERSet(type1))) |
|
||||||
{ |
|
||||||
fail("wrong value retrieved for type1(0)!"); |
|
||||||
} |
|
||||||
|
|
||||||
a = (Attribute)vec.get(1); |
|
||||||
if (!a.getAttrValues().equals(new DERSet(type2))) |
|
||||||
{ |
|
||||||
fail("wrong value retrieved for type1(1)!"); |
|
||||||
} |
|
||||||
|
|
||||||
a = (Attribute)vec.get(2); |
|
||||||
if (!a.getAttrValues().equals(new DERSet(type3))) |
|
||||||
{ |
|
||||||
fail("wrong value retrieved for type1(2)!"); |
|
||||||
} |
|
||||||
|
|
||||||
vec = table.getAll(type2); |
|
||||||
if (vec.size() != 1) |
|
||||||
{ |
|
||||||
fail("wrong vector size for multiple type2."); |
|
||||||
} |
|
||||||
|
|
||||||
vec = table.toASN1EncodableVector(); |
|
||||||
if (vec.size() != 4) |
|
||||||
{ |
|
||||||
fail("wrong vector size for multiple."); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public static void main( |
|
||||||
String[] args) |
|
||||||
{ |
|
||||||
runTest(new AttributeTableUnitTest()); |
|
||||||
} |
|
||||||
} |
|
@ -1,133 +0,0 @@ |
|||||||
package com.fr.third.org.bouncycastle.asn1.test; |
|
||||||
|
|
||||||
import java.security.SecureRandom; |
|
||||||
|
|
||||||
import com.fr.third.org.bouncycastle.asn1.ASN1InputStream; |
|
||||||
import com.fr.third.org.bouncycastle.asn1.ASN1OctetString; |
|
||||||
import com.fr.third.org.bouncycastle.asn1.ASN1Sequence; |
|
||||||
import com.fr.third.org.bouncycastle.asn1.DERIA5String; |
|
||||||
import com.fr.third.org.bouncycastle.asn1.DERNull; |
|
||||||
import com.fr.third.org.bouncycastle.asn1.DEROctetString; |
|
||||||
import com.fr.third.org.bouncycastle.asn1.oiw.OIWObjectIdentifiers; |
|
||||||
import com.fr.third.org.bouncycastle.asn1.x509.AlgorithmIdentifier; |
|
||||||
import com.fr.third.org.bouncycastle.asn1.x509.qualified.BiometricData; |
|
||||||
import com.fr.third.org.bouncycastle.asn1.x509.qualified.TypeOfBiometricData; |
|
||||||
import com.fr.third.org.bouncycastle.util.test.SimpleTest; |
|
||||||
|
|
||||||
public class BiometricDataUnitTest |
|
||||||
extends SimpleTest |
|
||||||
{ |
|
||||||
public String getName() |
|
||||||
{ |
|
||||||
return "BiometricData"; |
|
||||||
} |
|
||||||
|
|
||||||
private byte[] generateHash() |
|
||||||
{ |
|
||||||
SecureRandom rand = new SecureRandom(); |
|
||||||
byte[] bytes = new byte[20]; |
|
||||||
|
|
||||||
rand.nextBytes(bytes); |
|
||||||
|
|
||||||
return bytes; |
|
||||||
} |
|
||||||
|
|
||||||
public void performTest() |
|
||||||
throws Exception |
|
||||||
{ |
|
||||||
TypeOfBiometricData dataType = new TypeOfBiometricData(TypeOfBiometricData.HANDWRITTEN_SIGNATURE); |
|
||||||
AlgorithmIdentifier hashAlgorithm = new AlgorithmIdentifier(OIWObjectIdentifiers.idSHA1, DERNull.INSTANCE); |
|
||||||
ASN1OctetString dataHash = new DEROctetString(generateHash()); |
|
||||||
BiometricData bd = new BiometricData(dataType, hashAlgorithm, dataHash); |
|
||||||
|
|
||||||
checkConstruction(bd, dataType, hashAlgorithm, dataHash, null); |
|
||||||
|
|
||||||
DERIA5String dataUri = new DERIA5String("http://test"); |
|
||||||
|
|
||||||
bd = new BiometricData(dataType, hashAlgorithm, dataHash, dataUri); |
|
||||||
|
|
||||||
checkConstruction(bd, dataType, hashAlgorithm, dataHash, dataUri); |
|
||||||
|
|
||||||
bd = BiometricData.getInstance(null); |
|
||||||
|
|
||||||
if (bd != null) |
|
||||||
{ |
|
||||||
fail("null getInstance() failed."); |
|
||||||
} |
|
||||||
|
|
||||||
try |
|
||||||
{ |
|
||||||
BiometricData.getInstance(new Object()); |
|
||||||
|
|
||||||
fail("getInstance() failed to detect bad object."); |
|
||||||
} |
|
||||||
catch (IllegalArgumentException e) |
|
||||||
{ |
|
||||||
// expected
|
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private void checkConstruction( |
|
||||||
BiometricData bd, |
|
||||||
TypeOfBiometricData dataType, |
|
||||||
AlgorithmIdentifier hashAlgorithm, |
|
||||||
ASN1OctetString dataHash, |
|
||||||
DERIA5String dataUri) |
|
||||||
throws Exception |
|
||||||
{ |
|
||||||
checkValues(bd, dataType, hashAlgorithm, dataHash, dataUri); |
|
||||||
|
|
||||||
bd = BiometricData.getInstance(bd); |
|
||||||
|
|
||||||
checkValues(bd, dataType, hashAlgorithm, dataHash, dataUri); |
|
||||||
|
|
||||||
ASN1InputStream aIn = new ASN1InputStream(bd.toASN1Primitive().getEncoded()); |
|
||||||
|
|
||||||
ASN1Sequence seq = (ASN1Sequence)aIn.readObject(); |
|
||||||
|
|
||||||
bd = BiometricData.getInstance(seq); |
|
||||||
|
|
||||||
checkValues(bd, dataType, hashAlgorithm, dataHash, dataUri); |
|
||||||
} |
|
||||||
|
|
||||||
private void checkValues( |
|
||||||
BiometricData bd, |
|
||||||
TypeOfBiometricData dataType, |
|
||||||
AlgorithmIdentifier algID, |
|
||||||
ASN1OctetString dataHash, |
|
||||||
DERIA5String sourceDataURI) |
|
||||||
{ |
|
||||||
if (!bd.getTypeOfBiometricData().equals(dataType)) |
|
||||||
{ |
|
||||||
fail("types don't match."); |
|
||||||
} |
|
||||||
|
|
||||||
if (!bd.getHashAlgorithm().equals(algID)) |
|
||||||
{ |
|
||||||
fail("hash algorithms don't match."); |
|
||||||
} |
|
||||||
|
|
||||||
if (!bd.getBiometricDataHash().equals(dataHash)) |
|
||||||
{ |
|
||||||
fail("hash algorithms don't match."); |
|
||||||
} |
|
||||||
|
|
||||||
if (sourceDataURI != null) |
|
||||||
{ |
|
||||||
if (!bd.getSourceDataUri().equals(sourceDataURI)) |
|
||||||
{ |
|
||||||
fail("data uris don't match."); |
|
||||||
} |
|
||||||
} |
|
||||||
else if (bd.getSourceDataUri() != null) |
|
||||||
{ |
|
||||||
fail("data uri found when none expected."); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public static void main( |
|
||||||
String[] args) |
|
||||||
{ |
|
||||||
runTest(new BiometricDataUnitTest()); |
|
||||||
} |
|
||||||
} |
|
@ -1,22 +0,0 @@ |
|||||||
package com.fr.third.org.bouncycastle.asn1.test; |
|
||||||
|
|
||||||
public class BitStringConstantTester |
|
||||||
{ |
|
||||||
private static final int[] bits = |
|
||||||
{ |
|
||||||
1 << 7, 1 << 6, 1 << 5, 1 << 4, 1 << 3, 1 << 2, 1 << 1, 1 << 0, |
|
||||||
1 << 15, 1 << 14, 1 << 13, 1 << 12, 1 << 11, 1 << 10, 1 << 9, 1 << 8, |
|
||||||
1 << 23, 1 << 22, 1 << 21, 1 << 20, 1 << 19, 1 << 18, 1 << 17, 1 << 16, |
|
||||||
1 << 31, 1 << 30, 1 << 29, 1 << 28, 1 << 27, 1 << 26, 1 << 25, 1 << 24 |
|
||||||
}; |
|
||||||
|
|
||||||
public static void testFlagValueCorrect( |
|
||||||
int bitNo, |
|
||||||
int value) |
|
||||||
{ |
|
||||||
if (bits[bitNo] != value) |
|
||||||
{ |
|
||||||
throw new IllegalArgumentException("bit value " + bitNo + " wrong"); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -1,185 +0,0 @@ |
|||||||
package com.fr.third.org.bouncycastle.asn1.test; |
|
||||||
|
|
||||||
import java.io.IOException; |
|
||||||
|
|
||||||
import com.fr.third.org.bouncycastle.asn1.ASN1BitString; |
|
||||||
import com.fr.third.org.bouncycastle.asn1.ASN1Encoding; |
|
||||||
import com.fr.third.org.bouncycastle.asn1.ASN1Primitive; |
|
||||||
import com.fr.third.org.bouncycastle.asn1.DERBitString; |
|
||||||
import com.fr.third.org.bouncycastle.asn1.DLBitString; |
|
||||||
import com.fr.third.org.bouncycastle.asn1.x509.KeyUsage; |
|
||||||
import com.fr.third.org.bouncycastle.util.Arrays; |
|
||||||
import com.fr.third.org.bouncycastle.util.encoders.Hex; |
|
||||||
import com.fr.third.org.bouncycastle.util.test.SimpleTest; |
|
||||||
import com.fr.third.org.bouncycastle.util.test.TestResult; |
|
||||||
|
|
||||||
public class BitStringTest |
|
||||||
extends SimpleTest |
|
||||||
{ |
|
||||||
private void testZeroLengthStrings() |
|
||||||
throws Exception |
|
||||||
{ |
|
||||||
// basic construction
|
|
||||||
DERBitString s1 = new DERBitString(new byte[0], 0); |
|
||||||
|
|
||||||
// check getBytes()
|
|
||||||
s1.getBytes(); |
|
||||||
|
|
||||||
// check encoding/decoding
|
|
||||||
DERBitString derBit = (DERBitString)ASN1Primitive.fromByteArray(s1.getEncoded()); |
|
||||||
|
|
||||||
if (!Arrays.areEqual(s1.getEncoded(), Hex.decode("030100"))) |
|
||||||
{ |
|
||||||
fail("zero encoding wrong"); |
|
||||||
} |
|
||||||
|
|
||||||
try |
|
||||||
{ |
|
||||||
new DERBitString(null, 1); |
|
||||||
fail("exception not thrown"); |
|
||||||
} |
|
||||||
catch (NullPointerException e) |
|
||||||
{ |
|
||||||
if (!"'data' cannot be null".equals(e.getMessage())) |
|
||||||
{ |
|
||||||
fail("Unexpected exception: " + e.getMessage()); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
try |
|
||||||
{ |
|
||||||
new DERBitString(new byte[0], 1); |
|
||||||
fail("exception not thrown"); |
|
||||||
} |
|
||||||
catch (IllegalArgumentException e) |
|
||||||
{ |
|
||||||
if (!"zero length data with non-zero pad bits".equals(e.getMessage())) |
|
||||||
{ |
|
||||||
fail("Unexpected exception"); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
try |
|
||||||
{ |
|
||||||
new DERBitString(new byte[1], 8); |
|
||||||
fail("exception not thrown"); |
|
||||||
} |
|
||||||
catch (IllegalArgumentException e) |
|
||||||
{ |
|
||||||
if (!"pad bits cannot be greater than 7 or less than 0".equals(e.getMessage())) |
|
||||||
{ |
|
||||||
fail("Unexpected exception"); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
DERBitString s2 = new DERBitString(0); |
|
||||||
if (!Arrays.areEqual(s1.getEncoded(), s2.getEncoded())) |
|
||||||
{ |
|
||||||
fail("zero encoding wrong"); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private void testRandomPadBits() |
|
||||||
throws Exception |
|
||||||
{ |
|
||||||
byte[] test = Hex.decode("030206c0"); |
|
||||||
|
|
||||||
byte[] test1 = Hex.decode("030206f0"); |
|
||||||
byte[] test2 = Hex.decode("030206c1"); |
|
||||||
byte[] test3 = Hex.decode("030206c7"); |
|
||||||
byte[] test4 = Hex.decode("030206d1"); |
|
||||||
|
|
||||||
encodingCheck(test, test1); |
|
||||||
encodingCheck(test, test2); |
|
||||||
encodingCheck(test, test3); |
|
||||||
encodingCheck(test, test4); |
|
||||||
} |
|
||||||
|
|
||||||
private void encodingCheck(byte[] derData, byte[] dlData) |
|
||||||
throws IOException |
|
||||||
{ |
|
||||||
if (Arrays.areEqual(derData, ASN1Primitive.fromByteArray(dlData).getEncoded())) |
|
||||||
{ |
|
||||||
fail("failed DL check"); |
|
||||||
} |
|
||||||
ASN1BitString dl = DLBitString.getInstance(dlData); |
|
||||||
|
|
||||||
isTrue("DL test failed", dl instanceof DLBitString); |
|
||||||
if (!Arrays.areEqual(derData, ASN1Primitive.fromByteArray(dlData).getEncoded(ASN1Encoding.DER))) |
|
||||||
{ |
|
||||||
fail("failed DER check"); |
|
||||||
} |
|
||||||
try |
|
||||||
{ |
|
||||||
DERBitString.getInstance(dlData); |
|
||||||
fail("no exception"); |
|
||||||
} |
|
||||||
catch (IllegalArgumentException e) |
|
||||||
{ |
|
||||||
// ignore
|
|
||||||
} |
|
||||||
ASN1BitString der = DERBitString.getInstance(derData); |
|
||||||
isTrue("DER test failed", der instanceof DERBitString); |
|
||||||
} |
|
||||||
|
|
||||||
public void performTest() |
|
||||||
throws Exception |
|
||||||
{ |
|
||||||
KeyUsage k = new KeyUsage(KeyUsage.digitalSignature); |
|
||||||
if ((k.getBytes()[0] != (byte)KeyUsage.digitalSignature) || (k.getPadBits() != 7)) |
|
||||||
{ |
|
||||||
fail("failed digitalSignature"); |
|
||||||
} |
|
||||||
|
|
||||||
k = new KeyUsage(KeyUsage.nonRepudiation); |
|
||||||
if ((k.getBytes()[0] != (byte)KeyUsage.nonRepudiation) || (k.getPadBits() != 6)) |
|
||||||
{ |
|
||||||
fail("failed nonRepudiation"); |
|
||||||
} |
|
||||||
|
|
||||||
k = new KeyUsage(KeyUsage.keyEncipherment); |
|
||||||
if ((k.getBytes()[0] != (byte)KeyUsage.keyEncipherment) || (k.getPadBits() != 5)) |
|
||||||
{ |
|
||||||
fail("failed keyEncipherment"); |
|
||||||
} |
|
||||||
|
|
||||||
k = new KeyUsage(KeyUsage.cRLSign); |
|
||||||
if ((k.getBytes()[0] != (byte)KeyUsage.cRLSign) || (k.getPadBits() != 1)) |
|
||||||
{ |
|
||||||
fail("failed cRLSign"); |
|
||||||
} |
|
||||||
|
|
||||||
k = new KeyUsage(KeyUsage.decipherOnly); |
|
||||||
if ((k.getBytes()[1] != (byte)(KeyUsage.decipherOnly >> 8)) || (k.getPadBits() != 7)) |
|
||||||
{ |
|
||||||
fail("failed decipherOnly"); |
|
||||||
} |
|
||||||
|
|
||||||
// test for zero length bit string
|
|
||||||
try |
|
||||||
{ |
|
||||||
ASN1Primitive.fromByteArray(new DERBitString(new byte[0], 0).getEncoded()); |
|
||||||
} |
|
||||||
catch (IOException e) |
|
||||||
{ |
|
||||||
fail(e.toString()); |
|
||||||
} |
|
||||||
|
|
||||||
testRandomPadBits(); |
|
||||||
testZeroLengthStrings(); |
|
||||||
} |
|
||||||
|
|
||||||
public String getName() |
|
||||||
{ |
|
||||||
return "BitString"; |
|
||||||
} |
|
||||||
|
|
||||||
public static void main( |
|
||||||
String[] args) |
|
||||||
{ |
|
||||||
BitStringTest test = new BitStringTest(); |
|
||||||
TestResult result = test.perform(); |
|
||||||
|
|
||||||
System.out.println(result); |
|
||||||
} |
|
||||||
} |
|
@ -1,97 +0,0 @@ |
|||||||
package com.fr.third.org.bouncycastle.asn1.test; |
|
||||||
|
|
||||||
|
|
||||||
import com.fr.third.org.bouncycastle.asn1.cmc.BodyPartID; |
|
||||||
import com.fr.third.org.bouncycastle.util.test.SimpleTest; |
|
||||||
|
|
||||||
public class BodyPartIDTest |
|
||||||
extends SimpleTest |
|
||||||
{ |
|
||||||
|
|
||||||
|
|
||||||
public void performTest() |
|
||||||
throws Exception |
|
||||||
{ |
|
||||||
// Test correct encode / decode
|
|
||||||
|
|
||||||
|
|
||||||
{ |
|
||||||
// Test encode and decode from Long and from other instance of BodyPartID
|
|
||||||
BodyPartID bpd = new BodyPartID(10L); |
|
||||||
byte[] b = bpd.getEncoded(); |
|
||||||
BodyPartID resBpd = BodyPartID.getInstance(b); |
|
||||||
isEquals("Correct / Encode byte array", resBpd.getID(), bpd.getID()); |
|
||||||
|
|
||||||
BodyPartID rootPartID = new BodyPartID(12L); |
|
||||||
bpd = BodyPartID.getInstance(rootPartID); |
|
||||||
b = bpd.getEncoded(); |
|
||||||
resBpd = BodyPartID.getInstance(b); |
|
||||||
isEquals("Correct / Encode byte array", resBpd.getID(), rootPartID.getID()); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
{ |
|
||||||
// Test lower limit, should not throw exception
|
|
||||||
try |
|
||||||
{ |
|
||||||
new BodyPartID(0); |
|
||||||
} |
|
||||||
catch (Throwable t) |
|
||||||
{ |
|
||||||
fail("Unexpected exception: " + t.getMessage(), t); |
|
||||||
} |
|
||||||
|
|
||||||
// Test below lower range
|
|
||||||
try |
|
||||||
{ |
|
||||||
new BodyPartID(-1); |
|
||||||
fail("Expecting IllegalArgumentException because of outside lower range"); |
|
||||||
} |
|
||||||
catch (Throwable e) |
|
||||||
{ |
|
||||||
if (!(e instanceof IllegalArgumentException)) |
|
||||||
{ |
|
||||||
fail("Expecting only IllegalArgumentException, got:" + e.getMessage(), e); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
{ |
|
||||||
// Test upper limit, should not throw exception.
|
|
||||||
try |
|
||||||
{ |
|
||||||
new BodyPartID(4294967295L); |
|
||||||
} |
|
||||||
catch (Throwable t) |
|
||||||
{ |
|
||||||
fail("Unexpected exception: " + t.getMessage(), t); |
|
||||||
} |
|
||||||
|
|
||||||
// Test above upper range
|
|
||||||
try |
|
||||||
{ |
|
||||||
new BodyPartID(4294967296L); |
|
||||||
fail("Expecting IllegalArgumentException because of outside upper range"); |
|
||||||
} |
|
||||||
catch (Throwable e) |
|
||||||
{ |
|
||||||
if (!(e instanceof IllegalArgumentException)) |
|
||||||
{ |
|
||||||
fail("Expecting only IllegalArgumentException, got:" + e.getMessage(), e); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public String getName() |
|
||||||
{ |
|
||||||
return "BodyPartIDTest"; |
|
||||||
} |
|
||||||
|
|
||||||
public static void main(String[] args) |
|
||||||
throws Exception |
|
||||||
{ |
|
||||||
runTest(new BodyPartIDTest()); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
@ -1,71 +0,0 @@ |
|||||||
package com.fr.third.org.bouncycastle.asn1.test; |
|
||||||
|
|
||||||
import java.util.Random; |
|
||||||
|
|
||||||
import com.fr.third.org.bouncycastle.asn1.DERSequence; |
|
||||||
import com.fr.third.org.bouncycastle.asn1.cmc.BodyPartID; |
|
||||||
import com.fr.third.org.bouncycastle.asn1.cmc.BodyPartList; |
|
||||||
import com.fr.third.org.bouncycastle.util.test.SimpleTest; |
|
||||||
|
|
||||||
|
|
||||||
/** |
|
||||||
* Test the creation of BodyPartListTest and encoding and decoding. |
|
||||||
*/ |
|
||||||
public class BodyPartListTest |
|
||||||
extends SimpleTest |
|
||||||
{ |
|
||||||
|
|
||||||
public void performTest() |
|
||||||
throws Exception |
|
||||||
{ |
|
||||||
Random rand = new Random(); |
|
||||||
{ |
|
||||||
BodyPartID[] bpid = new BodyPartID[Math.abs(rand.nextInt()) % 20]; |
|
||||||
for (int t = 0; t < bpid.length; t++) |
|
||||||
{ |
|
||||||
bpid[t] = new BodyPartID(Math.abs(rand.nextLong() % 4294967295L)); |
|
||||||
} |
|
||||||
BodyPartList bpl = new BodyPartList(bpid); |
|
||||||
DERSequence _bpl = (DERSequence)bpl.toASN1Primitive(); |
|
||||||
byte[] b = bpl.getEncoded(); |
|
||||||
|
|
||||||
//
|
|
||||||
// Decode and compare results.
|
|
||||||
//
|
|
||||||
|
|
||||||
BodyPartList resList = BodyPartList.getInstance(b); |
|
||||||
DERSequence _resList = (DERSequence)resList.toASN1Primitive(); |
|
||||||
|
|
||||||
isEquals(_bpl.size(), _resList.size()); |
|
||||||
|
|
||||||
for (int j = 0; j < _bpl.size(); j++) |
|
||||||
{ |
|
||||||
isEquals(_resList.getObjectAt(j), _bpl.getObjectAt(j)); |
|
||||||
} |
|
||||||
} |
|
||||||
{ |
|
||||||
//
|
|
||||||
// Compare when same thing instantiated via different constructors.
|
|
||||||
//
|
|
||||||
|
|
||||||
BodyPartID bpid = new BodyPartID(Math.abs(rand.nextLong() % 4294967295L)); |
|
||||||
BodyPartList bpidList = new BodyPartList(bpid); // Single entry constructor.
|
|
||||||
BodyPartList resList = new BodyPartList(new BodyPartID[]{bpid}); // Array constructor.
|
|
||||||
|
|
||||||
DERSequence _bpidList = (DERSequence)bpidList.toASN1Primitive(); |
|
||||||
DERSequence _resList = (DERSequence)resList.toASN1Primitive(); |
|
||||||
|
|
||||||
isEquals(_bpidList, _resList); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public String getName() |
|
||||||
{ |
|
||||||
return "BodyPartListTest"; |
|
||||||
} |
|
||||||
|
|
||||||
public static void main(String[] args) |
|
||||||
{ |
|
||||||
runTest(new BodyPartListTest()); |
|
||||||
} |
|
||||||
} |
|
@ -1,69 +0,0 @@ |
|||||||
package com.fr.third.org.bouncycastle.asn1.test; |
|
||||||
|
|
||||||
|
|
||||||
import java.util.Random; |
|
||||||
|
|
||||||
import com.fr.third.org.bouncycastle.asn1.DERSequence; |
|
||||||
import com.fr.third.org.bouncycastle.asn1.cmc.BodyPartID; |
|
||||||
import com.fr.third.org.bouncycastle.asn1.cmc.BodyPartPath; |
|
||||||
import com.fr.third.org.bouncycastle.util.test.SimpleTest; |
|
||||||
|
|
||||||
public class BodyPartPathTest |
|
||||||
extends SimpleTest |
|
||||||
{ |
|
||||||
|
|
||||||
public void performTest() |
|
||||||
throws Exception |
|
||||||
{ |
|
||||||
Random rand = new Random(); |
|
||||||
{ |
|
||||||
BodyPartID[] bpid = new BodyPartID[Math.abs(rand.nextInt()) % 20]; |
|
||||||
for (int t = 0; t < bpid.length; t++) |
|
||||||
{ |
|
||||||
bpid[t] = new BodyPartID(Math.abs(rand.nextLong() % 4294967295L)); |
|
||||||
} |
|
||||||
BodyPartPath bpp = new BodyPartPath(bpid); |
|
||||||
DERSequence _bpp = (DERSequence)bpp.toASN1Primitive(); |
|
||||||
byte[] b = bpp.getEncoded(); |
|
||||||
|
|
||||||
//
|
|
||||||
// Decode and compare results.
|
|
||||||
//
|
|
||||||
|
|
||||||
BodyPartPath resList = BodyPartPath.getInstance(b); |
|
||||||
DERSequence _resList = (DERSequence)resList.toASN1Primitive(); |
|
||||||
|
|
||||||
isEquals(_bpp.size(), _resList.size()); |
|
||||||
|
|
||||||
for (int j = 0; j < _bpp.size(); j++) |
|
||||||
{ |
|
||||||
isEquals(_resList.getObjectAt(j), _bpp.getObjectAt(j)); |
|
||||||
} |
|
||||||
} |
|
||||||
{ |
|
||||||
//
|
|
||||||
// Compare when same thing instantiated via different constructors.
|
|
||||||
//
|
|
||||||
|
|
||||||
BodyPartID bpid = new BodyPartID(Math.abs(rand.nextLong() % 4294967295L)); |
|
||||||
BodyPartPath bpidList = new BodyPartPath(bpid); // Single entry constructor.
|
|
||||||
BodyPartPath resList = new BodyPartPath(new BodyPartID[]{bpid}); // Array constructor.
|
|
||||||
|
|
||||||
DERSequence _bpidList = (DERSequence)bpidList.toASN1Primitive(); |
|
||||||
DERSequence _resList = (DERSequence)resList.toASN1Primitive(); |
|
||||||
|
|
||||||
isEquals(_bpidList, _resList); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public String getName() |
|
||||||
{ |
|
||||||
return "BodyPartPathTest"; |
|
||||||
} |
|
||||||
|
|
||||||
public static void main(String[] args) |
|
||||||
{ |
|
||||||
runTest(new BodyPartPathTest()); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -1,79 +0,0 @@ |
|||||||
package com.fr.third.org.bouncycastle.asn1.test; |
|
||||||
|
|
||||||
import java.util.Random; |
|
||||||
|
|
||||||
import com.fr.third.org.bouncycastle.asn1.cmc.BodyPartID; |
|
||||||
import com.fr.third.org.bouncycastle.asn1.cmc.BodyPartPath; |
|
||||||
import com.fr.third.org.bouncycastle.asn1.cmc.BodyPartReference; |
|
||||||
import com.fr.third.org.bouncycastle.util.test.SimpleTest; |
|
||||||
|
|
||||||
|
|
||||||
public class BodyPartReferenceTest |
|
||||||
extends SimpleTest |
|
||||||
{ |
|
||||||
|
|
||||||
public String getName() |
|
||||||
{ |
|
||||||
return "BodyPartReferenceTest"; |
|
||||||
} |
|
||||||
|
|
||||||
public void performTest() |
|
||||||
throws Exception |
|
||||||
{ |
|
||||||
Random rand = new Random(); |
|
||||||
BodyPartReference ch0 = null; |
|
||||||
BodyPartReference ch1 = null; |
|
||||||
{ |
|
||||||
// Choice 1
|
|
||||||
BodyPartID id = new BodyPartID(Math.abs(rand.nextLong() % 4294967295L)); |
|
||||||
|
|
||||||
ch0 = new BodyPartReference(id); |
|
||||||
byte[] b = ch0.getEncoded(); |
|
||||||
|
|
||||||
BodyPartReference brRes = BodyPartReference.getInstance(b); |
|
||||||
isEquals(brRes, ch0); |
|
||||||
} |
|
||||||
|
|
||||||
{ |
|
||||||
// Choice 2
|
|
||||||
|
|
||||||
BodyPartID[] bpid = new BodyPartID[Math.abs(rand.nextInt()) % 20]; |
|
||||||
for (int t = 0; t < bpid.length; t++) |
|
||||||
{ |
|
||||||
bpid[t] = new BodyPartID(Math.abs(rand.nextLong() % 4294967295L)); |
|
||||||
} |
|
||||||
|
|
||||||
ch1 = new BodyPartReference(new BodyPartPath(bpid)); |
|
||||||
byte[] b = ch1.getEncoded(); |
|
||||||
|
|
||||||
BodyPartReference brRes = BodyPartReference.getInstance(b); |
|
||||||
isEquals(brRes, ch1); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
{ |
|
||||||
// Test choice alternatives are not equal.
|
|
||||||
BodyPartID id = new BodyPartID(Math.abs(rand.nextLong() % 4294967295L)); |
|
||||||
|
|
||||||
ch0 = new BodyPartReference(id); |
|
||||||
ch1 = new BodyPartReference(new BodyPartPath(id)); |
|
||||||
|
|
||||||
try |
|
||||||
{ |
|
||||||
isEquals(ch0, ch1); |
|
||||||
fail("Must not be equal."); |
|
||||||
} |
|
||||||
catch (Throwable t) |
|
||||||
{ |
|
||||||
// Ignored
|
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
public static void main(String[] args) |
|
||||||
{ |
|
||||||
runTest(new BodyPartReferenceTest()); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -1,76 +0,0 @@ |
|||||||
package com.fr.third.org.bouncycastle.asn1.test; |
|
||||||
|
|
||||||
import com.fr.third.org.bouncycastle.asn1.ASN1Encoding; |
|
||||||
import com.fr.third.org.bouncycastle.asn1.cmc.CertificationRequest; |
|
||||||
import com.fr.third.org.bouncycastle.util.Arrays; |
|
||||||
import com.fr.third.org.bouncycastle.util.encoders.Base64; |
|
||||||
import com.fr.third.org.bouncycastle.util.test.SimpleTest; |
|
||||||
|
|
||||||
public class CMCCertificationRequestTest |
|
||||||
extends SimpleTest |
|
||||||
{ |
|
||||||
byte[] req1 = Base64.decode( |
|
||||||
"MIHoMIGTAgEAMC4xDjAMBgNVBAMTBVRlc3QyMQ8wDQYDVQQKEwZBbmFUb20xCzAJBgNVBAYTAlNF" |
|
||||||
+ "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALlEt31Tzt2MlcOljvacJgzQVhmlMoqAOgqJ9Pgd3Gux" |
|
||||||
+ "Z7/WcIlgW4QCB7WZT21O1YoghwBhPDMcNGrHei9kHQkCAwEAAaAAMA0GCSqGSIb3DQEBBQUAA0EA" |
|
||||||
+ "NDEI4ecNtJ3uHwGGlitNFq9WxcoZ0djbQJ5hABMotav6gtqlrwKXY2evaIrsNwkJtNdwwH18aQDU" |
|
||||||
+ "KCjOuBL38Q=="); |
|
||||||
|
|
||||||
byte[] req2 = Base64.decode( |
|
||||||
"MIIB6TCCAVICAQAwgagxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRQwEgYDVQQH" |
|
||||||
+ "EwtTYW50YSBDbGFyYTEMMAoGA1UEChMDQUJCMVEwTwYDVQQLHEhQAAAAAAAAAG8AAAAAAAAAdwAA" |
|
||||||
+ "AAAAAABlAAAAAAAAAHIAAAAAAAAAIAAAAAAAAABUAAAAAAAAABxIAAAAAAAARAAAAAAAAAAxDTAL" |
|
||||||
+ "BgNVBAMTBGJsdWUwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANETRZ+6occCOrFxNhfKIp4C" |
|
||||||
+ "mMkxwhBNb7TnnahpbM9O0r4hrBPcfYuL7u9YX/jN0YNUP+/CiT39HhSe/bikaBPDEyNsl988I8vX" |
|
||||||
+ "piEdgxYq/+LTgGHbjRsRYCkPtmzwBbuBldNF8bV7pu0v4UScSsExmGqqDlX1TbPU8KkPU1iTAgMB" |
|
||||||
+ "AAGgADANBgkqhkiG9w0BAQQFAAOBgQAFbrs9qUwh93CtETk7DeUD5HcdCnxauo1bck44snSV6MZV" |
|
||||||
+ "OCIGaYu1501kmhEvAtVVRr6SEHwimfQDDIjnrWwYsEr/DT6tkTZAbfRd3qUu3iKjT0H0vlUZp0hJ" |
|
||||||
+ "66mINtBM84uZFBfoXiWY8M3FuAnGmvy6ah/dYtJorTxLKiGkew=="); |
|
||||||
|
|
||||||
public String getName() |
|
||||||
{ |
|
||||||
return "CMCCertificationRequestTest"; |
|
||||||
} |
|
||||||
|
|
||||||
public void certReqTest( |
|
||||||
String testName, |
|
||||||
byte[] req) |
|
||||||
throws Exception |
|
||||||
{ |
|
||||||
CertificationRequest r = CertificationRequest.getInstance(req); |
|
||||||
|
|
||||||
byte[] bytes = r.getEncoded(ASN1Encoding.DER); |
|
||||||
|
|
||||||
if (bytes.length != req.length) |
|
||||||
{ |
|
||||||
fail(testName + " failed length test"); |
|
||||||
} |
|
||||||
|
|
||||||
for (int i = 0; i != req.length; i++) |
|
||||||
{ |
|
||||||
if (bytes[i] != req[i]) |
|
||||||
{ |
|
||||||
fail(testName + " failed comparison test"); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public void performTest() |
|
||||||
throws Exception |
|
||||||
{ |
|
||||||
certReqTest("req1", req1); |
|
||||||
certReqTest("req2", req2); |
|
||||||
|
|
||||||
CertificationRequest a = CertificationRequest.getInstance(req1); |
|
||||||
CertificationRequest b = new CertificationRequest(a.getSubject(), a.getSubjectPublicKeyAlgorithm(), a.getSubjectPublicKey(), a.getAttributes(), a.getSignatureAlgorithm(), a.getSignature()); |
|
||||||
|
|
||||||
isTrue(Arrays.areEqual(a.getEncoded(), b.getEncoded())); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
public static void main( |
|
||||||
String[] args) |
|
||||||
{ |
|
||||||
runTest(new CMCCertificationRequestTest()); |
|
||||||
} |
|
||||||
} |
|
@ -1,96 +0,0 @@ |
|||||||
package com.fr.third.org.bouncycastle.asn1.test; |
|
||||||
|
|
||||||
import java.lang.reflect.Field; |
|
||||||
import java.util.HashMap; |
|
||||||
import java.util.Iterator; |
|
||||||
import java.util.Map; |
|
||||||
|
|
||||||
import com.fr.third.org.bouncycastle.asn1.ASN1Integer; |
|
||||||
import com.fr.third.org.bouncycastle.asn1.cmc.CMCFailInfo; |
|
||||||
import com.fr.third.org.bouncycastle.util.test.SimpleTest; |
|
||||||
|
|
||||||
public class CMCFailInfoTest |
|
||||||
extends SimpleTest |
|
||||||
{ |
|
||||||
|
|
||||||
// From Page 68, CMC: Structures RFC 5272
|
|
||||||
private static Object[][] types = new Object[][]{ |
|
||||||
{"badAlg", new Long(0L) }, |
|
||||||
{"badMessageCheck", new Long(1L) }, |
|
||||||
{"badRequest", new Long(2L) }, |
|
||||||
{"badTime", new Long(3L) }, |
|
||||||
{"badCertId", new Long(4L) }, |
|
||||||
{"unsupportedExt", new Long(5L) }, |
|
||||||
{"mustArchiveKeys", new Long(6L) }, |
|
||||||
{"badIdentity", new Long(7L) }, |
|
||||||
{"popRequired", new Long(8L) }, |
|
||||||
{"popFailed", new Long(9L) }, |
|
||||||
{"noKeyReuse", new Long(10L) }, |
|
||||||
{"internalCAError", new Long(11L) }, |
|
||||||
{"tryLater", new Long(12L) }, |
|
||||||
{"authDataFail", new Long(13L)} |
|
||||||
}; |
|
||||||
private static Map typesMap = new HashMap(); |
|
||||||
|
|
||||||
static |
|
||||||
{ |
|
||||||
for (int t = 0; t < types.length; t++) |
|
||||||
{ |
|
||||||
typesMap.put(types[t][1], types[t][0]); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
public void performTest() |
|
||||||
throws Exception |
|
||||||
{ |
|
||||||
|
|
||||||
//
|
|
||||||
// Check that range has changed and this test has not been updated or vice versa.
|
|
||||||
// It is intended to act as a double check on the addition of CMCFailInfo presets by
|
|
||||||
// requiring this test to be updated equally to ensure it will pass.
|
|
||||||
//
|
|
||||||
|
|
||||||
Field rangeField = CMCFailInfo.class.getDeclaredField("range"); |
|
||||||
rangeField.setAccessible(true); |
|
||||||
|
|
||||||
Map range = (Map)rangeField.get(null); |
|
||||||
|
|
||||||
isEquals("Range in CMCFailInfo does not match test data.",range.size(), types.length); |
|
||||||
|
|
||||||
for (Iterator rangeKeys = range.keySet().iterator(); rangeKeys.hasNext(); ) |
|
||||||
{ Object j = rangeKeys.next(); |
|
||||||
if (!typesMap.containsKey(new Long(((ASN1Integer)j).getValue().longValue()))) { |
|
||||||
fail("The 'range' map in CMCFailInfo contains a value not in the test ('typesMap') map, value was: "+j.toString()); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
for (Iterator typeKeys = typesMap.keySet().iterator(); typeKeys.hasNext(); ) |
|
||||||
{ Object j = typeKeys.next(); |
|
||||||
if (!range.containsKey(new ASN1Integer(((Long)j).longValue()))) { |
|
||||||
fail("The 'typesMap' map in CMCFailInfoTest contains a value not in the CMCFailInfo ('range') map, value was: "+j.toString()); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
// Test encoding / decoding
|
|
||||||
//
|
|
||||||
|
|
||||||
byte[] b = CMCFailInfo.authDataFail.getEncoded(); |
|
||||||
CMCFailInfo r = CMCFailInfo.getInstance(b); |
|
||||||
isEquals(r,CMCFailInfo.authDataFail); |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
public String getName() |
|
||||||
{ |
|
||||||
return "CMCFailInfoTest"; |
|
||||||
} |
|
||||||
|
|
||||||
public static void main(String[] args) |
|
||||||
{ |
|
||||||
runTest(new CMCFailInfoTest()); |
|
||||||
} |
|
||||||
} |
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue