Bouncy Castle Cryptography Library 1.87

org.bouncycastle.asn1.test
Class SetSortedElementsTest

java.lang.Object
  extended byjunit.framework.Assert
      extended byjunit.framework.TestCase
          extended byorg.bouncycastle.asn1.test.SetSortedElementsTest
All Implemented Interfaces:
junit.framework.Test

public class SetSortedElementsTest
extends junit.framework.TestCase

ASN1Set keeps its elements in DER order, in sortedElements, alongside the elements themselves: set at construction when that order is already known, otherwise computed and cached by the first DER encoding.


Constructor Summary
SetSortedElementsTest()
           
 
Method Summary
 void testConcurrentFirstDEREncoding()
          The first DER encoding of a SET not built in DER order - every SET the parser reads - sorts a copy of the elements and caches it.
 void testDERSetArrayConstructorRecordsSortedCopy()
          The array constructor copies the caller's array, and sorts the copy for a DERSet; it used to record the caller's array, unsorted, as the DER order (github #2550).
 void testSingleElementSetDoesNotRetainCallerArray()
          A set of one element needs no sorting, so it records its elements as their DER order at construction - for DLSet and BERSet too.
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, runTest, setName, setUp, tearDown, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SetSortedElementsTest

public SetSortedElementsTest()
Method Detail

testDERSetArrayConstructorRecordsSortedCopy

public void testDERSetArrayConstructorRecordsSortedCopy()
The array constructor copies the caller's array, and sorts the copy for a DERSet; it used to record the caller's array, unsorted, as the DER order (github #2550).


testSingleElementSetDoesNotRetainCallerArray

public void testSingleElementSetDoesNotRetainCallerArray()
                                                  throws java.io.IOException
A set of one element needs no sorting, so it records its elements as their DER order at construction - for DLSet and BERSet too. That has to be the set's own copy: when it was the caller's array, whatever the caller later stored there became the set's DER encoding and what equals() compared, while getObjectAt(), hashCode() and the DL/BER encodings kept the original.

Throws:
java.io.IOException

testConcurrentFirstDEREncoding

public void testConcurrentFirstDEREncoding()
                                    throws java.lang.Exception
The first DER encoding of a SET not built in DER order - every SET the parser reads - sorts a copy of the elements and caches it. The copy used to be cached before it was sorted, so another thread encoding the same SET at the same time could take it unsorted, or part way through the sort with some elements present twice and others missing. With the early publication nearly every concurrent encoding here came out wrong; a pass cannot prove the race absent, but a failure is never spurious.

Throws:
java.lang.Exception

Bouncy Castle Cryptography Library 1.87