Browse Source

Merge pull request #3218 in CORE/base-third from feature/10.0 to bugfix/10.0

* commit '8e72b1897c29267295ea818c11f79b61e2168aa2':
  DEC-19773 refactor: itext适配新bouncycastle
  DEC-19773 refactor: 升级bouncycastle库
  REPORT-55330 修复Bitmap实现bug
bugfix/10.0
superman 3 years ago
parent
commit
a3d3fec4e7
  1. 2
      fine-bouncycastle/readme.md
  2. 25
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1BitString.java
  3. 2
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1GeneralizedTime.java
  4. 4
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1Generator.java
  5. 23
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1InputStream.java
  6. 9
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1Object.java
  7. 4
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1OctetString.java
  8. 10
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1OutputStream.java
  9. 10
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1Sequence.java
  10. 6
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1Set.java
  11. 8
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1TaggedObject.java
  12. 144
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/BERConstructedOctetString.java
  13. 39
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/BERGenerator.java
  14. 89
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/BEROctetString.java
  15. 9
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/BEROutputStream.java
  16. 67
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ConstructedOctetStream.java
  17. 26
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DERBMPString.java
  18. 18
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DEREncodableVector.java
  19. 37
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DEREnumerated.java
  20. 30
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DERInteger.java
  21. 5
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DERNull.java
  22. 24
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DERObjectIdentifier.java
  23. 10
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DEROutputStream.java
  24. 58
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DERSequenceParser.java
  25. 58
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DERSetParser.java
  26. 153
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DERT61UTF8String.java
  27. 9
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DERTags.java
  28. 2
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DLExternal.java
  29. 10
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DLOutputStream.java
  30. 52
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DLSequenceParser.java
  31. 52
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DLSetParser.java
  32. 34
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DefiniteLengthInputStream.java
  33. 2
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/IndefiniteLengthInputStream.java
  34. 13
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/LazyConstructionEnumeration.java
  35. 11
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/LimitedInputStream.java
  36. 5
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/anssi/package.html
  37. 5
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/bc/package.html
  38. 5
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/bsi/package.html
  39. 5
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/cmc/package.html
  40. 25
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/cmp/CertOrEncCert.java
  41. 30
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/cmp/CertifiedKeyPair.java
  42. 2
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/cmp/PKIHeaderBuilder.java
  43. 5
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/cmp/package.html
  44. 5
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/cms/ecc/package.html
  45. 5
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/cms/package.html
  46. 5
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/crmf/package.html
  47. 32
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/cryptopro/ECGOST3410NamedCurves.java
  48. 5
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/cryptopro/package.html
  49. 5
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/dvcs/package.html
  50. 5
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/eac/package.html
  51. 6
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/esf/package.html
  52. 5
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ess/package.html
  53. 5
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/est/package.html
  54. 5
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/gm/package.html
  55. 5
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/gnu/package.html
  56. 5
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/iana/package.html
  57. 5
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/icao/package.html
  58. 22
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/isara/IsaraObjectIdentifiers.java
  59. 5
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/isismtt/ocsp/package.html
  60. 5
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/isismtt/package.html
  61. 5
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/isismtt/x509/package.html
  62. 5
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/iso/package.html
  63. 5
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/kisa/package.html
  64. 5
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/microsoft/package.html
  65. 13
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/misc/MiscObjectIdentifiers.java
  66. 5
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/misc/package.html
  67. 5
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/mozilla/package.html
  68. 114
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/nist/KMACwithSHAKE128_params.java
  69. 114
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/nist/KMACwithSHAKE256_params.java
  70. 8
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/nist/NISTObjectIdentifiers.java
  71. 5
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/nist/package.html
  72. 5
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/nsri/package.html
  73. 5
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ntt/package.html
  74. 5
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ocsp/OCSPResponseStatus.java
  75. 5
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ocsp/package.html
  76. 5
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/oiw/package.html
  77. 5
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/package.html
  78. 2
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/pkcs/CertBag.java
  79. 32
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/pkcs/PKCSObjectIdentifiers.java
  80. 11
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/pkcs/PrivateKeyInfo.java
  81. 5
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/pkcs/package.html
  82. 5
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/rosstandart/package.html
  83. 5
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/sec/package.html
  84. 5
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/smime/package.html
  85. 5
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/teletrust/package.html
  86. 365
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/ASN1IntegerTest.java
  87. 89
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/ASN1UnitTest.java
  88. 69
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/AdditionalInformationSyntaxUnitTest.java
  89. 97
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/AdmissionSyntaxUnitTest.java
  90. 86
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/AdmissionsUnitTest.java
  91. 144
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/AttributeTableUnitTest.java
  92. 133
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/BiometricDataUnitTest.java
  93. 22
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/BitStringConstantTester.java
  94. 185
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/BitStringTest.java
  95. 97
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/BodyPartIDTest.java
  96. 71
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/BodyPartListTest.java
  97. 69
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/BodyPartPathTest.java
  98. 79
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/BodyPartReferenceTest.java
  99. 76
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/CMCCertificationRequestTest.java
  100. 96
      fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/CMCFailInfoTest.java
  101. Some files were not shown because too many files have changed in this diff Show More

2
fine-bouncycastle/readme.md

@ -1,2 +1,2 @@
版本:1.64<br>
版本:1.67<br>
源码:https://www.bouncycastle.org/latest_releases.html<br>

25
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1BitString.java

@ -203,7 +203,15 @@ public abstract class ASN1BitString
public byte[] getBytes()
{
return derForm(data, padBits);
if (0 == data.length)
{
return data;
}
byte[] rv = Arrays.clone(data);
// DER requires pad bits be zero
rv[data.length - 1] &= (0xFF << padBits);
return rv;
}
public int getPadBits()
@ -269,21 +277,6 @@ public abstract class ASN1BitString
return derA == derB;
}
/**
* @deprecated Will be hidden/removed.
*/
protected static byte[] derForm(byte[] data, int padBits)
{
if (0 == data.length)
{
return data;
}
byte[] rv = Arrays.clone(data);
// DER requires pad bits be zero
rv[data.length - 1] &= (0xFF << padBits);
return rv;
}
static ASN1BitString fromInputStream(int length, InputStream stream)
throws IOException
{

2
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1GeneralizedTime.java

@ -271,7 +271,7 @@ public class ASN1GeneralizedTime
}
}
catch (ParseException e)
{ e.printStackTrace();
{
// we'll do our best and ignore daylight savings
}

4
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1Generator.java

@ -7,12 +7,14 @@ import java.io.OutputStream;
*/
public abstract class ASN1Generator
{
// TODO This is problematic if we want an isolating buffer for all ASN.1 writes
protected OutputStream _out;
/**
* Base constructor.
*
* @param out the end output stream that object encodings are written to.
* @param out
* the end output stream that object encodings are written to.
*/
public ASN1Generator(OutputStream out)
{

23
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1InputStream.java

@ -383,23 +383,20 @@ public class ASN1InputStream
throws IOException
{
int len = defIn.getRemaining();
if (defIn.getRemaining() < tmpBuffers.length)
if (len >= tmpBuffers.length)
{
byte[] buf = tmpBuffers[len];
if (buf == null)
{
buf = tmpBuffers[len] = new byte[len];
}
Streams.readFully(defIn, buf);
return buf;
return defIn.toByteArray();
}
else
byte[] buf = tmpBuffers[len];
if (buf == null)
{
return defIn.toByteArray();
buf = tmpBuffers[len] = new byte[len];
}
defIn.readAllIntoByteArray(buf);
return buf;
}
private static char[] getBMPCharBuffer(DefiniteLengthInputStream defIn)

9
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1Object.java

@ -72,15 +72,6 @@ public abstract class ASN1Object
return this.toASN1Primitive().equals(other.toASN1Primitive());
}
/**
* @deprecated use toASN1Primitive()
* @return the underlying primitive type.
*/
public ASN1Primitive toASN1Object()
{
return this.toASN1Primitive();
}
/**
* Return true if obj is a byte array and represents an object with the given tag value.
*

4
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1OctetString.java

@ -133,7 +133,7 @@ public abstract class ASN1OctetString
*/
if (taggedObject.isExplicit())
{
ASN1OctetString singleSegment = ASN1OctetString.getInstance(o);
ASN1OctetString singleSegment = getInstance(o);
if (taggedObject instanceof BERTaggedObject)
{
@ -194,7 +194,7 @@ public abstract class ASN1OctetString
{
try
{
return ASN1OctetString.getInstance(ASN1Primitive.fromByteArray((byte[])obj));
return getInstance(fromByteArray((byte[])obj));
}
catch (IOException e)
{

10
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1OutputStream.java

@ -264,16 +264,6 @@ public class ASN1OutputStream
}
}
/**
* @deprecated Will be removed.
*/
protected void writeNull()
throws IOException
{
write(BERTags.NULL);
write(0x00);
}
public void writeObject(ASN1Encodable obj) throws IOException
{
if (null == obj)

10
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1Sequence.java

@ -177,7 +177,7 @@ public abstract class ASN1Sequence
/**
* Create a SEQUENCE containing one object.
* @param obj the object to be put in the SEQUENCE.
* @param element the object to be put in the SEQUENCE.
*/
protected ASN1Sequence(ASN1Encodable element)
{
@ -205,7 +205,7 @@ public abstract class ASN1Sequence
/**
* Create a SEQUENCE containing an array of objects.
* @param array the array of objects to be put in the SEQUENCE.
* @param elements the array of objects to be put in the SEQUENCE.
*/
protected ASN1Sequence(ASN1Encodable[] elements)
{
@ -245,11 +245,11 @@ public abstract class ASN1Sequence
public Object nextElement()
{
if (pos >= elements.length)
if (pos < elements.length)
{
throw new NoSuchElementException("ASN1Sequence Enumeration");
return elements[pos++];
}
return elements[pos++];
throw new NoSuchElementException();
}
};
}

6
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1Set.java

@ -312,11 +312,11 @@ public abstract class ASN1Set
public Object nextElement()
{
if (pos >= elements.length)
if (pos < elements.length)
{
throw new NoSuchElementException("ASN1Set Enumeration");
return elements[pos++];
}
return elements[pos++];
throw new NoSuchElementException();
}
};
}

8
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1TaggedObject.java

@ -123,14 +123,6 @@ public abstract class ASN1TaggedObject
return explicit;
}
/**
* @deprecated Will be removed (always returns false).
*/
public boolean isEmpty()
{
return false;
}
/**
* Return whatever was following the tag.
* <p>

144
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/BERConstructedOctetString.java

@ -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);
}
}

39
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/BERGenerator.java

@ -7,25 +7,23 @@ import java.io.OutputStream;
* Base class for generators for indefinite-length structures.
*/
public class BERGenerator
extends ASN1Generator
extends
ASN1Generator
{
private boolean _tagged = false;
private boolean _isExplicit;
private int _tagNo;
private boolean _tagged = false;
private boolean _isExplicit;
private int _tagNo;
protected BERGenerator(
OutputStream out)
protected BERGenerator(OutputStream out)
{
super(out);
}
protected BERGenerator(
OutputStream out,
int tagNo,
boolean isExplicit)
protected BERGenerator(OutputStream out, int tagNo, boolean isExplicit)
{
super(out);
// TODO Check proper handling of implicit tagging
_tagged = true;
_isExplicit = isExplicit;
_tagNo = tagNo;
@ -35,18 +33,14 @@ public class BERGenerator
{
return _out;
}
private void writeHdr(
int tag)
throws IOException
private void writeHdr(int tag) throws IOException
{
_out.write(tag);
_out.write(0x80);
}
protected void writeBERHeader(
int tag)
throws IOException
protected void writeBERHeader(int tag) throws IOException
{
if (_tagged)
{
@ -58,7 +52,7 @@ public class BERGenerator
writeHdr(tag);
}
else
{
{
if ((tag & BERTags.CONSTRUCTED) != 0)
{
writeHdr(tagNum | BERTags.CONSTRUCTED);
@ -75,12 +69,11 @@ public class BERGenerator
}
}
protected void writeBEREnd()
throws IOException
protected void writeBEREnd() throws IOException
{
_out.write(0x00);
_out.write(0x00);
if (_tagged && _isExplicit) // write extra end for tag header
{
_out.write(0x00);

89
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/BEROctetString.java

@ -3,7 +3,7 @@ package com.fr.third.org.bouncycastle.asn1;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Vector;
import java.util.NoSuchElementException;
/**
* ASN.1 OctetStrings, with indefinite length rules, and <i>constructed form</i> support.
@ -22,7 +22,7 @@ import java.util.Vector;
public class BEROctetString
extends ASN1OctetString
{
private static final int DEFAULT_LENGTH = 1000;
private static final int DEFAULT_CHUNK_SIZE = 1000;
private final int chunkSize;
private final ASN1OctetString[] octs;
@ -39,13 +39,7 @@ public class BEROctetString
{
try
{
DEROctetString o = (DEROctetString)octs[i];
bOut.write(o.getOctets());
}
catch (ClassCastException e)
{
throw new IllegalArgumentException(octs[i].getClass().getName() + " found in input should only contain DEROctetString");
bOut.write(octs[i].getOctets());
}
catch (IOException e)
{
@ -63,7 +57,7 @@ public class BEROctetString
public BEROctetString(
byte[] string)
{
this(string, DEFAULT_LENGTH);
this(string, DEFAULT_CHUNK_SIZE);
}
/**
@ -75,7 +69,7 @@ public class BEROctetString
public BEROctetString(
ASN1OctetString[] octs)
{
this(octs, DEFAULT_LENGTH);
this(octs, DEFAULT_CHUNK_SIZE);
}
/**
@ -111,15 +105,6 @@ public class BEROctetString
this.chunkSize = chunkSize;
}
/**
* Return a concatenated byte array of all the octets making up the constructed OCTET STRING
* @return the full OCTET STRING.
*/
public byte[] getOctets()
{
return string;
}
/**
* Return the OCTET STRINGs that make up this string.
*
@ -129,7 +114,28 @@ public class BEROctetString
{
if (octs == null)
{
return generateOcts().elements();
return new Enumeration()
{
int pos = 0;
public boolean hasMoreElements()
{
return pos < string.length;
}
public Object nextElement()
{
if (pos < string.length)
{
int length = Math.min(string.length - pos, chunkSize);
byte[] chunk = new byte[length];
System.arraycopy(string, pos, chunk, 0, length);
pos += length;
return new DEROctetString(chunk);
}
throw new NoSuchElementException();
}
};
}
return new Enumeration()
@ -143,37 +149,15 @@ public class BEROctetString
public Object nextElement()
{
return octs[counter++];
if (counter < octs.length)
{
return octs[counter++];
}
throw new NoSuchElementException();
}
};
}
private Vector generateOcts()
{
Vector vec = new Vector();
for (int i = 0; i < string.length; i += chunkSize)
{
int end;
if (i + chunkSize > string.length)
{
end = string.length;
}
else
{
end = i + chunkSize;
}
byte[] nStr = new byte[end - i];
System.arraycopy(string, i, nStr, 0, nStr.length);
vec.addElement(new DEROctetString(nStr));
}
return vec;
}
boolean isConstructed()
{
return true;
@ -191,15 +175,6 @@ public class BEROctetString
return 2 + length + 2;
}
/**
* @deprecated
*/
public void encode(ASN1OutputStream out)
throws IOException
{
out.writeObject(this);
}
void encode(ASN1OutputStream out, boolean withTag) throws IOException
{
out.writeEncodedIndef(withTag, BERTags.CONSTRUCTED | BERTags.OCTET_STRING, getObjects());

9
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/BEROutputStream.java

@ -5,10 +5,8 @@ import java.io.OutputStream;
/**
* A class which writes indefinite and definite length objects. Objects which specify DER will be
* encoded accordingly, but DL or BER objects will be encoded as defined.
*
* @deprecated Will be removed from public API.
*/
public class BEROutputStream
class BEROutputStream
extends ASN1OutputStream
{
/**
@ -16,11 +14,8 @@ public class BEROutputStream
*
* @param os
* target output stream.
*
* @deprecated Use {@link ASN1OutputStream#create(OutputStream, String)} with
* {@link ASN1Encoding#BER} instead.
*/
public BEROutputStream(OutputStream os)
BEROutputStream(OutputStream os)
{
super(os);
}

67
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ConstructedOctetStream.java

@ -26,21 +26,14 @@ class ConstructedOctetStream
return -1;
}
ASN1Encodable asn1Obj = _parser.readObject();
if (asn1Obj == null)
ASN1OctetStringParser next = getNextParser();
if (next == null)
{
return -1;
}
if (!(asn1Obj instanceof ASN1OctetStringParser))
{
throw new IOException("unknown object encountered: " + asn1Obj.getClass());
}
ASN1OctetStringParser s = (ASN1OctetStringParser)asn1Obj;
_first = false;
_currentStream = s.getOctetStream();
_currentStream = next.getOctetStream();
}
int totalRead = 0;
@ -60,22 +53,14 @@ class ConstructedOctetStream
}
else
{
ASN1Encodable asn1Obj = _parser.readObject();
if (asn1Obj == null)
ASN1OctetStringParser next = getNextParser();
if (next == null)
{
_currentStream = null;
return totalRead < 1 ? -1 : totalRead;
}
if (!(asn1Obj instanceof ASN1OctetStringParser))
{
throw new IOException("unknown object encountered: " + asn1Obj.getClass());
}
ASN1OctetStringParser aos = (ASN1OctetStringParser)asn1Obj;
_currentStream = aos.getOctetStream();
_currentStream = next.getOctetStream();
}
}
}
@ -90,22 +75,14 @@ class ConstructedOctetStream
return -1;
}
ASN1Encodable asn1Obj = _parser.readObject();
if (asn1Obj == null)
ASN1OctetStringParser next = getNextParser();
if (next == null)
{
return -1;
}
if (!(asn1Obj instanceof ASN1OctetStringParser))
{
throw new IOException("unknown object encountered: " + asn1Obj.getClass());
}
ASN1OctetStringParser s = (ASN1OctetStringParser)asn1Obj;
_first = false;
_currentStream = s.getOctetStream();
_currentStream = next.getOctetStream();
}
for (;;)
@ -117,22 +94,30 @@ class ConstructedOctetStream
return b;
}
ASN1Encodable asn1Obj = _parser.readObject();
if (asn1Obj == null)
ASN1OctetStringParser next = getNextParser();
if (next == null)
{
_currentStream = null;
return -1;
}
if (!(asn1Obj instanceof ASN1OctetStringParser))
{
throw new IOException("unknown object encountered: " + asn1Obj.getClass());
}
_currentStream = next.getOctetStream();
}
}
ASN1OctetStringParser s = (ASN1OctetStringParser)asn1Obj;
private ASN1OctetStringParser getNextParser() throws IOException
{
ASN1Encodable asn1Obj = _parser.readObject();
if (asn1Obj == null)
{
return null;
}
_currentStream = s.getOctetStream();
if (asn1Obj instanceof ASN1OctetStringParser)
{
return (ASN1OctetStringParser)asn1Obj;
}
throw new IOException("unknown object encountered: " + asn1Obj.getClass());
}
}

26
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DERBMPString.java

@ -81,9 +81,21 @@ public class DERBMPString
DERBMPString(
byte[] string)
{
char[] cs = new char[string.length / 2];
if (string == null)
{
throw new NullPointerException("'string' cannot be null");
}
int byteLen = string.length;
if (0 != (byteLen & 1))
{
throw new IllegalArgumentException("malformed BMPString encoding encountered");
}
int charLen = byteLen / 2;
char[] cs = new char[charLen];
for (int i = 0; i != cs.length; i++)
for (int i = 0; i != charLen; i++)
{
cs[i] = (char)((string[2 * i] << 8) | (string[2 * i + 1] & 0xff));
}
@ -93,6 +105,11 @@ public class DERBMPString
DERBMPString(char[] string)
{
if (string == null)
{
throw new NullPointerException("'string' cannot be null");
}
this.string = string;
}
@ -103,6 +120,11 @@ public class DERBMPString
public DERBMPString(
String string)
{
if (string == null)
{
throw new NullPointerException("'string' cannot be null");
}
this.string = string.toCharArray();
}

18
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DEREncodableVector.java

@ -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()
{
}
}

37
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DEREnumerated.java

@ -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);
}
}

30
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DERInteger.java

@ -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);
}
}

5
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DERNull.java

@ -14,10 +14,7 @@ public class DERNull
private static final byte[] zeroBytes = new byte[0];
/**
* @deprecated use DERNull.INSTANCE
*/
public DERNull()
private DERNull()
{
}

24
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DERObjectIdentifier.java

@ -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);
}
}

10
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DEROutputStream.java

@ -5,17 +5,11 @@ import java.io.OutputStream;
/**
* Stream that outputs encoding based on distinguished encoding rules.
*
* @deprecated Will be removed from public API.
*/
public class DEROutputStream
class DEROutputStream
extends ASN1OutputStream
{
/**
* @deprecated Use {@link ASN1OutputStream#create(OutputStream, String)} with
* {@link ASN1Encoding#DER} instead.
*/
public DEROutputStream(OutputStream os)
DEROutputStream(OutputStream os)
{
super(os);
}

58
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DERSequenceParser.java

@ -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());
}
}
}

58
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DERSetParser.java

@ -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);
}
}
}

153
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DERT61UTF8String.java

@ -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);
}
}

9
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DERTags.java

@ -1,9 +0,0 @@
package com.fr.third.org.bouncycastle.asn1;
/**
* @deprecated use BERTags
*/
public interface DERTags
extends BERTags
{
}

2
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DLExternal.java

@ -82,7 +82,7 @@ public class DLExternal
{
baos.write(dataValueDescriptor.getEncoded(ASN1Encoding.DL));
}
DERTaggedObject obj = new DERTaggedObject(true, encoding, externalContent);
ASN1TaggedObject obj = new DLTaggedObject(true, encoding, externalContent);
baos.write(obj.getEncoded(ASN1Encoding.DL));
out.writeEncoded(withTag, BERTags.CONSTRUCTED, BERTags.EXTERNAL, baos.toByteArray());

10
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DLOutputStream.java

@ -5,17 +5,11 @@ import java.io.OutputStream;
/**
* Stream that outputs encoding based on definite length.
*
* @deprecated Will be removed from public API.
*/
public class DLOutputStream
class DLOutputStream
extends ASN1OutputStream
{
/**
* @deprecated Use {@link ASN1OutputStream#create(OutputStream, String)} with
* {@link ASN1Encoding#DL} instead.
*/
public DLOutputStream(OutputStream os)
DLOutputStream(OutputStream os)
{
super(os);
}

52
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DLSequenceParser.java

@ -1,12 +1,60 @@
package com.fr.third.org.bouncycastle.asn1;
import java.io.IOException;
/**
* 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)
{
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());
}
}
}

52
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DLSetParser.java

@ -1,12 +1,60 @@
package com.fr.third.org.bouncycastle.asn1;
import java.io.IOException;
/**
* 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)
{
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);
}
}
}

34
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DefiniteLengthInputStream.java

@ -23,7 +23,7 @@ class DefiniteLengthInputStream
int length,
int limit)
{
super(in, limit, length);
super(in, limit);
if (length < 0)
{
@ -91,6 +91,33 @@ class DefiniteLengthInputStream
return numRead;
}
void readAllIntoByteArray(byte[] buf)
throws IOException
{
if (_remaining != buf.length)
{
throw new IllegalArgumentException("buffer length not right for data");
}
if (_remaining == 0)
{
return;
}
// make sure it's safe to do this!
int limit = getLimit();
if (_remaining >= limit)
{
throw new IOException("corrupted stream - out of bounds length found: " + _remaining + " >= " + limit);
}
if ((_remaining -= Streams.readFully(_in, buf)) != 0)
{
throw new EOFException("DEF length " + _originalLength + " object truncated by " + _remaining);
}
setParentEofDetect(true);
}
byte[] toByteArray()
throws IOException
{
@ -100,9 +127,10 @@ class DefiniteLengthInputStream
}
// make sure it's safe to do this!
if (_remaining >= this.getLimit())
int limit = getLimit();
if (_remaining >= limit)
{
throw new IOException("corrupted stream - out of bounds length found: " + _remaining + " >= " + this.getLimit());
throw new IOException("corrupted stream - out of bounds length found: " + _remaining + " >= " + limit);
}
byte[] bytes = new byte[_remaining];

2
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/IndefiniteLengthInputStream.java

@ -17,7 +17,7 @@ class IndefiniteLengthInputStream
int limit)
throws IOException
{
super(in, limit, limit);
super(in, limit);
_b1 = in.read();
_b2 = in.read();

13
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/LazyConstructionEnumeration.java

@ -2,6 +2,7 @@ package com.fr.third.org.bouncycastle.asn1;
import java.io.IOException;
import java.util.Enumeration;
import java.util.NoSuchElementException;
class LazyConstructionEnumeration
implements Enumeration
@ -22,11 +23,13 @@ class LazyConstructionEnumeration
public Object nextElement()
{
Object o = nextObj;
nextObj = readObject();
return o;
if (nextObj != null)
{
Object o = nextObj;
nextObj = readObject();
return o;
}
throw new NoSuchElementException();
}
private Object readObject()

11
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/LimitedInputStream.java

@ -10,16 +10,13 @@ abstract class LimitedInputStream
{
protected final InputStream _in;
private int _limit;
private int _length;
LimitedInputStream(
InputStream in,
int limit,
int length)
int limit)
{
this._in = in;
this._limit = limit;
this._length = length;
}
int getLimit()
@ -27,12 +24,6 @@ abstract class LimitedInputStream
return _limit;
}
int getRemaining()
{
// TODO: maybe one day this can become more accurate
return _length;
}
protected void setParentEofDetect(boolean on)
{
if (_in instanceof IndefiniteLengthInputStream)

5
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/anssi/package.html

@ -1,5 +0,0 @@
<html>
<body bgcolor="#ffffff">
Support classes for the French ANSSI EC curves.
</body>
</html>

5
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/bc/package.html

@ -1,5 +0,0 @@
<html>
<body bgcolor="#ffffff">
ASN.1 classes specific to the Bouncy Castle APIs.
</body>
</html>

5
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/bsi/package.html

@ -1,5 +0,0 @@
<html>
<body bgcolor="#ffffff">
ASN.1 classes specific to the Bundesamt f&uuml;r Sicherheit in der Informationstechnik (BSI) standards.
</body>
</html>

5
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/cmc/package.html

@ -1,5 +0,0 @@
<html>
<body bgcolor="#ffffff">
Support classes for Certificate Management over CMS (CMC) - RFC 5272 and RFC 6402.
</body>
</html>

25
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/cmp/CertOrEncCert.java

@ -5,6 +5,7 @@ import com.fr.third.org.bouncycastle.asn1.ASN1Object;
import com.fr.third.org.bouncycastle.asn1.ASN1Primitive;
import com.fr.third.org.bouncycastle.asn1.ASN1TaggedObject;
import com.fr.third.org.bouncycastle.asn1.DERTaggedObject;
import com.fr.third.org.bouncycastle.asn1.crmf.EncryptedKey;
import com.fr.third.org.bouncycastle.asn1.crmf.EncryptedValue;
public class CertOrEncCert
@ -12,7 +13,7 @@ public class CertOrEncCert
implements ASN1Choice
{
private CMPCertificate certificate;
private EncryptedValue encryptedCert;
private EncryptedKey encryptedKey;
private CertOrEncCert(ASN1TaggedObject tagged)
{
@ -22,7 +23,7 @@ public class CertOrEncCert
}
else if (tagged.getTagNo() == 1)
{
encryptedCert = EncryptedValue.getInstance(tagged.getObject());
encryptedKey = EncryptedKey.getInstance(tagged.getObject());
}
else
{
@ -62,7 +63,17 @@ public class CertOrEncCert
throw new IllegalArgumentException("'encryptedCert' cannot be null");
}
this.encryptedCert = encryptedCert;
this.encryptedKey = new EncryptedKey(encryptedCert);
}
public CertOrEncCert(EncryptedKey encryptedKey)
{
if (encryptedKey == null)
{
throw new IllegalArgumentException("'encryptedKey' cannot be null");
}
this.encryptedKey = encryptedKey;
}
public CMPCertificate getCertificate()
@ -70,16 +81,16 @@ public class CertOrEncCert
return certificate;
}
public EncryptedValue getEncryptedCert()
public EncryptedKey getEncryptedCert()
{
return encryptedCert;
return encryptedKey;
}
/**
* <pre>
* CertOrEncCert ::= CHOICE {
* certificate [0] CMPCertificate,
* encryptedCert [1] EncryptedValue
* encryptedCert [1] EncryptedKey
* }
* </pre>
* @return a basic ASN.1 object representation.
@ -91,6 +102,6 @@ public class CertOrEncCert
return new DERTaggedObject(true, 0, certificate);
}
return new DERTaggedObject(true, 1, encryptedCert);
return new DERTaggedObject(true, 1, encryptedKey);
}
}

30
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/cmp/CertifiedKeyPair.java

@ -7,6 +7,7 @@ import com.fr.third.org.bouncycastle.asn1.ASN1Sequence;
import com.fr.third.org.bouncycastle.asn1.ASN1TaggedObject;
import com.fr.third.org.bouncycastle.asn1.DERSequence;
import com.fr.third.org.bouncycastle.asn1.DERTaggedObject;
import com.fr.third.org.bouncycastle.asn1.crmf.EncryptedKey;
import com.fr.third.org.bouncycastle.asn1.crmf.EncryptedValue;
import com.fr.third.org.bouncycastle.asn1.crmf.PKIPublicationInfo;
@ -14,7 +15,7 @@ import com.fr.third.org.bouncycastle.asn1.crmf.PKIPublicationInfo;
* <pre>
* CertifiedKeyPair ::= SEQUENCE {
* certOrEncCert CertOrEncCert,
* privateKey [0] EncryptedValue OPTIONAL,
* privateKey [0] EncryptedKey OPTIONAL,
* -- see [CRMF] for comment on encoding
* publicationInfo [1] PKIPublicationInfo OPTIONAL
* }
@ -24,7 +25,7 @@ public class CertifiedKeyPair
extends ASN1Object
{
private CertOrEncCert certOrEncCert;
private EncryptedValue privateKey;
private EncryptedKey privateKey;
private PKIPublicationInfo publicationInfo;
private CertifiedKeyPair(ASN1Sequence seq)
@ -38,7 +39,7 @@ public class CertifiedKeyPair
ASN1TaggedObject tagged = ASN1TaggedObject.getInstance(seq.getObjectAt(1));
if (tagged.getTagNo() == 0)
{
privateKey = EncryptedValue.getInstance(tagged.getObject());
privateKey = EncryptedKey.getInstance(tagged.getObject());
}
else
{
@ -47,7 +48,7 @@ public class CertifiedKeyPair
}
else
{
privateKey = EncryptedValue.getInstance(ASN1TaggedObject.getInstance(seq.getObjectAt(1)).getObject());
privateKey = EncryptedKey.getInstance(ASN1TaggedObject.getInstance(seq.getObjectAt(1)).getObject());
publicationInfo = PKIPublicationInfo.getInstance(ASN1TaggedObject.getInstance(seq.getObjectAt(2)).getObject());
}
}
@ -71,12 +72,12 @@ public class CertifiedKeyPair
public CertifiedKeyPair(
CertOrEncCert certOrEncCert)
{
this(certOrEncCert, null, null);
this(certOrEncCert, (EncryptedKey)null, null);
}
public CertifiedKeyPair(
CertOrEncCert certOrEncCert,
EncryptedValue privateKey,
EncryptedKey privateKey,
PKIPublicationInfo publicationInfo)
{
if (certOrEncCert == null)
@ -89,12 +90,27 @@ public class CertifiedKeyPair
this.publicationInfo = publicationInfo;
}
public CertifiedKeyPair(
CertOrEncCert certOrEncCert,
EncryptedValue privateKey,
PKIPublicationInfo publicationInfo)
{
if (certOrEncCert == null)
{
throw new IllegalArgumentException("'certOrEncCert' cannot be null");
}
this.certOrEncCert = certOrEncCert;
this.privateKey = (privateKey != null) ? new EncryptedKey(privateKey) : (EncryptedKey)null;
this.publicationInfo = publicationInfo;
}
public CertOrEncCert getCertOrEncCert()
{
return certOrEncCert;
}
public EncryptedValue getPrivateKey()
public EncryptedKey getPrivateKey()
{
return privateKey;
}

2
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/cmp/PKIHeaderBuilder.java

@ -76,7 +76,7 @@ public class PKIHeaderBuilder
return setRecipKID(kid == null ? null : new DEROctetString(kid));
}
public PKIHeaderBuilder setRecipKID(DEROctetString kid)
public PKIHeaderBuilder setRecipKID(ASN1OctetString kid)
{
recipKID = kid;

5
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/cmp/package.html

@ -1,5 +0,0 @@
<html>
<body bgcolor="#ffffff">
Support classes useful for encoding and supporting PKIX-CMP as described RFC 4210.
</body>
</html>

5
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/cms/ecc/package.html

@ -1,5 +0,0 @@
<html>
<body bgcolor="#ffffff">
Support classes for CMS ECC - RFC 5753/3278.
</body>
</html>

5
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/cms/package.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>

5
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/crmf/package.html

@ -1,5 +0,0 @@
<html>
<body bgcolor="#ffffff">
Support classes useful for encoding and supporting PKIX-CRMF as described RFC 4211.
</body>
</html>

32
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/cryptopro/ECGOST3410NamedCurves.java

@ -6,6 +6,8 @@ import java.util.Hashtable;
import com.fr.third.org.bouncycastle.asn1.ASN1ObjectIdentifier;
import com.fr.third.org.bouncycastle.asn1.rosstandart.RosstandartObjectIdentifiers;
import com.fr.third.org.bouncycastle.asn1.x9.X9ECParameters;
import com.fr.third.org.bouncycastle.asn1.x9.X9ECPoint;
import com.fr.third.org.bouncycastle.crypto.params.ECDomainParameters;
import com.fr.third.org.bouncycastle.math.ec.ECConstants;
import com.fr.third.org.bouncycastle.math.ec.ECCurve;
@ -222,13 +224,21 @@ public class ECGOST3410NamedCurves
* isn't present.
*
* @param oid an object identifier representing a named parameters, if present.
*
* @deprecated Use {@link #getByOIDX9(ASN1ObjectIdentifier)} instead.
*/
public static ECDomainParameters getByOID(
ASN1ObjectIdentifier oid)
public static ECDomainParameters getByOID(ASN1ObjectIdentifier oid)
{
return (ECDomainParameters)params.get(oid);
}
public static X9ECParameters getByOIDX9(ASN1ObjectIdentifier oid)
{
ECDomainParameters ec = (ECDomainParameters)params.get(oid);
return ec == null ? null : new X9ECParameters(ec.getCurve(), new X9ECPoint(ec.getG(), false), ec.getN(),
ec.getH(), ec.getSeed());
}
/**
* returns an enumeration containing the name strings for parameters
* contained in this structure.
@ -238,17 +248,19 @@ public class ECGOST3410NamedCurves
return names.elements();
}
public static ECDomainParameters getByName(
String name)
/**
* @deprecated Use {@link #getByNameX9(String)} instead.
*/
public static ECDomainParameters getByName(String name)
{
ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier)objIds.get(name);
return oid == null ? null : (ECDomainParameters)params.get(oid);
}
if (oid != null)
{
return (ECDomainParameters)params.get(oid);
}
return null;
public static X9ECParameters getByNameX9(String name)
{
ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier)objIds.get(name);
return oid == null ? null : getByOIDX9(oid);
}
/**

5
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/cryptopro/package.html

@ -1,5 +0,0 @@
<html>
<body bgcolor="#ffffff">
Support classes for CRYPTO-PRO related objects - such as GOST identifiers.
</body>
</html>

5
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/dvcs/package.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>

5
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/eac/package.html

@ -1,5 +0,0 @@
<html>
<body bgcolor="#ffffff">
ASN.1 classes specific to the Bundesamt f&uuml;r Sicherheit in der Informationstechnik (BSI) Technical Guideline Advanced Security Mechanisms for Machine Readable Travel Documents.
</body>
</html>

6
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/esf/package.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>

5
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ess/package.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>

5
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/est/package.html

@ -1,5 +0,0 @@
<html>
<body bgcolor="#ffffff">
Support classes for Enrollment over Secure Transport (EST) - RFC 7030.
</body>
</html>

5
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/gm/package.html

@ -1,5 +0,0 @@
<html>
<body bgcolor="#ffffff">
Support classes for Chinese Standard (GM) standard curves and algorithms.
</body>
</html>

5
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/gnu/package.html

@ -1,5 +0,0 @@
<html>
<body bgcolor="#ffffff">
ASN.1 classes specific to the GNU APIs and applications.
</body>
</html>

5
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/iana/package.html

@ -1,5 +0,0 @@
<html>
<body bgcolor="#ffffff">
ASN.1 classes specific to the Internet Assigned Numbers Authority (IANA).
</body>
</html>

5
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/icao/package.html

@ -1,5 +0,0 @@
<html>
<body bgcolor="#ffffff">
ICAO ASN.1 classes for electronic passport.
</body>
</html>

22
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/isara/IsaraObjectIdentifiers.java

@ -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");
}

5
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/isismtt/ocsp/package.html

@ -1,5 +0,0 @@
<html>
<body bgcolor="#ffffff">
Support classes for the ISIS-MTT profile for OCSP.
</body>
</html>

5
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/isismtt/package.html

@ -1,5 +0,0 @@
<html>
<body bgcolor="#ffffff">
Support classes for the ISIS-MTT Project.
</body>
</html>

5
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/isismtt/x509/package.html

@ -1,5 +0,0 @@
<html>
<body bgcolor="#ffffff">
Support classes for the ISIS-MTT X.509 Certificate Extensions.
</body>
</html>

5
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/iso/package.html

@ -1,5 +0,0 @@
<html>
<body bgcolor="#ffffff">
Support classes for various ISO Standards.
</body>
</html>

5
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/kisa/package.html

@ -1,5 +0,0 @@
<html>
<body bgcolor="#ffffff">
Support classes for the Korea Information Security Agency (KISA) standard - SEED algorithm.
</body>
</html>

5
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/microsoft/package.html

@ -1,5 +0,0 @@
<html>
<body bgcolor="#ffffff">
Support for Microsoft specific ASN.1 classes and object identifiers.
</body>
</html>

13
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/misc/MiscObjectIdentifiers.java

@ -101,6 +101,12 @@ public interface MiscObjectIdentifiers
*/
ASN1ObjectIdentifier cast5CBC = entrust.branch("66.10");
//
// HMAC-SHA1 hMAC-SHA1 OBJECT IDENTIFIER ::= { iso(1) identified-organization(3)
// dod(6) internet(1) security(5) mechanisms(5) 8 1 2 }
//
ASN1ObjectIdentifier hMAC_SHA1 = new ASN1ObjectIdentifier("1.3.6.1.5.5.8.1.2");
//
// Ascom
//
@ -135,4 +141,11 @@ public interface MiscObjectIdentifiers
//
// Scrypt
ASN1ObjectIdentifier id_scrypt = new ASN1ObjectIdentifier("1.3.6.1.4.1.11591.4.11");
// Composite key/signature oid - prototyping
//
// id-alg-composite OBJECT IDENTIFIER ::= {
// iso(1) identified-organization(3) dod(6) internet(1) private(4)
// enterprise(1) OpenCA(18227) Algorithms(2) id-alg-composite(1) }
ASN1ObjectIdentifier id_alg_composite = new ASN1ObjectIdentifier("1.3.6.1.4.1.18227.2.1");
}

5
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/misc/package.html

@ -1,5 +0,0 @@
<html>
<body bgcolor="#ffffff">
Miscellaneous object identifiers and objects.
</body>
</html>

5
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/mozilla/package.html

@ -1,5 +0,0 @@
<html>
<body bgcolor="#ffffff">
Support classes useful for encoding objects used by mozilla.
</body>
</html>

114
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/nist/KMACwithSHAKE128_params.java

@ -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);
}
}

114
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/nist/KMACwithSHAKE256_params.java

@ -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);
}
}

8
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/nist/NISTObjectIdentifiers.java

@ -51,6 +51,14 @@ public interface NISTObjectIdentifiers
static final ASN1ObjectIdentifier id_hmacWithSHA3_384 = hashAlgs.branch("15");
/** 2.16.840.1.101.3.4.2.16 */
static final ASN1ObjectIdentifier id_hmacWithSHA3_512 = hashAlgs.branch("16");
/** 2.16.840.1.101.3.4.2.17 */
static final ASN1ObjectIdentifier id_shake128_len = hashAlgs.branch("17");
/** 2.16.840.1.101.3.4.2.18 */
static final ASN1ObjectIdentifier id_shake256_len = hashAlgs.branch("18");
/** 2.16.840.1.101.3.4.2.19 */
static final ASN1ObjectIdentifier id_KmacWithSHAKE128 = hashAlgs.branch("19");
/** 2.16.840.1.101.3.4.2.20 */
static final ASN1ObjectIdentifier id_KmacWithSHAKE256 = hashAlgs.branch("20");
/** 2.16.840.1.101.3.4.1 */
static final ASN1ObjectIdentifier aes = nistAlgorithm.branch("1");

5
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/nist/package.html

@ -1,5 +0,0 @@
<html>
<body bgcolor="#ffffff">
Support classes for NIST related objects.
</body>
</html>

5
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/nsri/package.html

@ -1,5 +0,0 @@
<html>
<body bgcolor="#ffffff">
Support classes algorithms from the Korean National Security Research Institute.
</body>
</html>

5
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ntt/package.html

@ -1,5 +0,0 @@
<html>
<body bgcolor="#ffffff">
ASN.1 classes relevant to the standards produced by Nippon Telegraph and Telephone.
</body>
</html>

5
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ocsp/OCSPResponseStatus.java

@ -78,6 +78,11 @@ public class OCSPResponseStatus
return null;
}
public int getIntValue()
{
return value.intValueExact();
}
public BigInteger getValue()
{
return value.getValue();

5
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ocsp/package.html

@ -1,5 +0,0 @@
<html>
<body bgcolor="#ffffff">
Support classes useful for encoding and supporting OCSP objects.
</body>
</html>

5
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/oiw/package.html

@ -1,5 +0,0 @@
<html>
<body bgcolor="#ffffff">
Objects and OID for the support of ISO OIW.
</body>
</html>

5
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/package.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>

2
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/pkcs/CertBag.java

@ -19,7 +19,7 @@ public class CertBag
private CertBag(
ASN1Sequence seq)
{
this.certId = (ASN1ObjectIdentifier)seq.getObjectAt(0);
this.certId = ASN1ObjectIdentifier.getInstance(seq.getObjectAt(0));
this.certValue = ASN1TaggedObject.getInstance(seq.getObjectAt(1)).getObject();
}

32
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/pkcs/PKCSObjectIdentifiers.java

@ -253,6 +253,14 @@ public interface PKCSObjectIdentifiers
*/
ASN1ObjectIdentifier id_rsa_KEM = id_alg.branch("14");
/**
* id-alg-hss-lms-hashsig OBJECT IDENTIFIER ::= { iso(1)
* member-body(2) us(840) rsadsi(113549) pkcs(1) pkcs9(9)
* smime(16) alg(3) 17 }
*/
public static final ASN1ObjectIdentifier id_alg_hss_lms_hashsig = id_alg.branch("17");
/**
* <pre>
* id-alg-AEADChaCha20Poly1305 OBJECT IDENTIFIER ::=
@ -264,6 +272,30 @@ public interface PKCSObjectIdentifiers
*/
ASN1ObjectIdentifier id_alg_AEADChaCha20Poly1305 = id_alg.branch("18");
/**
* <pre>
* id-alg-hkdf-with-sha256 OBJECT IDENTIFIER ::= { iso(1) member-body(2)
* us(840) rsadsi(113549) pkcs(1) pkcs-9(9) smime(16) alg(3) 28 }
* </pre>
*/
ASN1ObjectIdentifier id_alg_hkdf_with_sha256 = id_alg.branch("28");
/**
* <pre>
* id-alg-hkdf-with-sha384 OBJECT IDENTIFIER ::= { iso(1) member-body(2)
* us(840) rsadsi(113549) pkcs(1) pkcs-9(9) smime(16) alg(3) 29 }
* </pre>
*/
ASN1ObjectIdentifier id_alg_hkdf_with_sha384 = id_alg.branch("29");
/**
* <pre>
* id-alg-hkdf-with-sha512 OBJECT IDENTIFIER ::= { iso(1) member-body(2)
* us(840) rsadsi(113549) pkcs(1) pkcs-9(9) smime(16) alg(3) 30 }
* </pre>
*/
ASN1ObjectIdentifier id_alg_hkdf_with_sha512 = id_alg.branch("30");
//
// id-cti OBJECT IDENTIFIER ::= {iso(1) member-body(2) usa(840)
// rsadsi(113549) pkcs(1) pkcs-9(9) smime(16) cti(6)}

11
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/pkcs/PrivateKeyInfo.java

@ -1,7 +1,6 @@
package com.fr.third.org.bouncycastle.asn1.pkcs;
import java.io.IOException;
import java.math.BigInteger;
import java.util.Enumeration;
import com.fr.third.org.bouncycastle.asn1.ASN1BitString;
@ -176,6 +175,11 @@ public class PrivateKeyInfo
}
}
public ASN1Integer getVersion()
{
return version;
}
public ASN1Set getAttributes()
{
return attributes;
@ -186,6 +190,11 @@ public class PrivateKeyInfo
return privateKeyAlgorithm;
}
public ASN1OctetString getPrivateKey()
{
return new DEROctetString(privateKey.getOctets());
}
public ASN1Encodable parsePrivateKey()
throws IOException
{

5
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/pkcs/package.html

@ -1,5 +0,0 @@
<html>
<body bgcolor="#ffffff">
Support classes useful for encoding and supporting the various RSA PKCS documents.
</body>
</html>

5
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/rosstandart/package.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>

5
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/sec/package.html

@ -1,5 +0,0 @@
<html>
<body bgcolor="#ffffff">
Classes for support of the SEC standard for Elliptic Curve.
</body>
</html>

5
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/smime/package.html

@ -1,5 +0,0 @@
<html>
<body bgcolor="#ffffff">
Support classes useful for encoding and supporting S/MIME.
</body>
</html>

5
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/teletrust/package.html

@ -1,5 +0,0 @@
<html>
<body bgcolor="#ffffff">
Support classes for TeleTrust related objects.
</body>
</html>

365
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/ASN1IntegerTest.java

@ -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());
}
}

89
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/ASN1UnitTest.java

@ -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.");
}
}
}

69
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/AdditionalInformationSyntaxUnitTest.java

@ -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());
}
}

97
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/AdmissionSyntaxUnitTest.java

@ -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());
}
}

86
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/AdmissionsUnitTest.java

@ -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());
}
}

144
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/AttributeTableUnitTest.java

@ -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());
}
}

133
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/BiometricDataUnitTest.java

@ -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());
}
}

22
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/BitStringConstantTester.java

@ -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");
}
}
}

185
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/BitStringTest.java

@ -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);
}
}

97
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/BodyPartIDTest.java

@ -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());
}
}

71
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/BodyPartListTest.java

@ -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());
}
}

69
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/BodyPartPathTest.java

@ -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());
}
}

79
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/BodyPartReferenceTest.java

@ -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());
}
}

76
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/CMCCertificationRequestTest.java

@ -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());
}
}

96
fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/CMCFailInfoTest.java

@ -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…
Cancel
Save