33import  de .christofreichardt .diagnosis .AbstractTracer ;
44import  de .christofreichardt .diagnosis .Traceable ;
55import  de .christofreichardt .diagnosis .TracerFactory ;
6- import  java .util .Arrays ;
7- import  java .util .HexFormat ;
8- import  java .util .NoSuchElementException ;
9- import  java .util .Random ;
6+ import  java .io .IOException ;
7+ import  java .nio .file .Files ;
8+ import  java .nio .file .Path ;
9+ import  java .security .SecureRandom ;
10+ import  java .util .*;
1011import  java .util .stream .Stream ;
1112import  org .assertj .core .api .WithAssertions ;
1213import  org .junit .jupiter .api .AfterAll ;
1314import  org .junit .jupiter .api .BeforeAll ;
15+ import  org .junit .jupiter .api .Test ;
1416import  org .junit .jupiter .api .TestInstance ;
1517import  org .junit .jupiter .params .ParameterizedTest ;
1618import  org .junit .jupiter .params .provider .MethodSource ;
1719
1820@ TestInstance (TestInstance .Lifecycle .PER_CLASS )
1921public  class  ASN1Unit  implements  Traceable , WithAssertions  {
2022
23+  Random  random  = new  SecureRandom ();
24+ 2125 @ BeforeAll 
22-  void  init () {
26+  void  init () throws IOException {
2327 AbstractTracer  tracer  = getCurrentTracer ();
2428 tracer .entry ("void" , this , "init()" );
2529
2630 try  {
31+  Path  path  = Path .of ("seeds" , "asn1-unit-seed.txt" );
32+  long  seed ;
33+  if  (Files .exists (path )) {
34+  tracer .out ().printfIndentln ("Using configured seed ..." );
35+  List <String > lines  = Files .readAllLines (path );
36+  seed  = Long .parseLong (lines .get (0 ));
37+  } else  {
38+  seed  = this .random .nextLong ();
39+  }
40+  tracer .out ().printfIndentln ("seed = %d" , seed );
41+  this .random .setSeed (seed );
2742 } finally  {
2843 tracer .wayout ();
2944 }
@@ -109,7 +124,7 @@ public String toString() {
109124 }
110125 }
111126
112-  static Stream <ASN1SeqTestParam > asn1IntSequenceStream (int  seqCount , int  maxIntByteCount , int  seqMaxByteCount , int  maxSeqLength ) {
127+  Stream <ASN1SeqTestParam > asn1IntSequenceStream (int  seqCount , int  maxIntByteCount , int  seqMaxByteCount , int  maxSeqLength ) {
113128 AbstractTracer  tracer  = TracerFactory .getInstance ().getCurrentPoolTracer ();
114129 tracer .entry ("Stream<ASN1IntSequence>" , ASN1Unit .class , "asn1IntSequenceStream()" );
115130
@@ -118,18 +133,17 @@ static Stream<ASN1SeqTestParam> asn1IntSequenceStream(int seqCount, int maxIntBy
118133 seqCount , maxIntByteCount , seqMaxByteCount , maxSeqLength );
119134
120135 ASN1SeqTestParam [] asn1SeqTestParams  = new  ASN1SeqTestParam [seqCount ];
121-  Random  random  = new  Random ();
122136 int  index  = 0 ;
123137 do  {
124-  int  intCount  = random .nextInt (maxSeqLength );
138+  int  intCount  = this . random .nextInt (maxSeqLength );
125139 tracer .out ().printfIndentln ("index = %d, intCount = %d" , index , intCount );
126140 int  sum  = 0 ;
127141 ASN1Integer [] asn1Integers  = new  ASN1Integer [intCount ];
128142 for  (int  j =0 ; j <intCount ; j ++) {
129-  int  length  = random .nextInt (maxIntByteCount );
143+  int  length  = this . random .nextInt (maxIntByteCount );
130144 tracer .out ().printfIndentln ("length = %d" , length );
131145 byte [] bytes  = new  byte [length ];
132-  random .nextBytes (bytes );
146+  this . random .nextBytes (bytes );
133147 ASN1Integer  asn1Integer  = ASN1Integer .fromBytes (bytes );
134148 tracer .out ().printfIndentln ("asn1Integer = %s" , asn1Integer );
135149 sum  += asn1Integer .asn1Length .rawLength ();
@@ -153,7 +167,7 @@ static Stream<ASN1SeqTestParam> asn1IntSequenceStream(int seqCount, int maxIntBy
153167 }
154168 }
155169
156-  static Stream <ASN1SeqTestParam > asn1IntShortSequenceStream () {
170+  Stream <ASN1SeqTestParam > asn1IntShortSequenceStream () {
157171 return  asn1IntSequenceStream (25 , 32 , ASN1 .SHORT_LENGTH , 16 );
158172 }
159173
@@ -243,7 +257,7 @@ void decodeSignaturesWithLongFormLength(ASN1_SignatureTestParam asn1_signatureTe
243257 }
244258 }
245259
246-  static Stream <ASN1SeqTestParam > asn1IntNotSoShortSequenceStream () {
260+  Stream <ASN1SeqTestParam > asn1IntNotSoShortSequenceStream () {
247261 return  asn1IntSequenceStream (25 , 64 , 255 , 8 );
248262 }
249263
@@ -269,6 +283,23 @@ void randomNotSoShortSequencesWithShortInts(ASN1SeqTestParam asn1SeqTestParam) {
269283 }
270284 }
271285
286+  @ Test 
287+  void  seeding () {
288+  AbstractTracer  tracer  = getCurrentTracer ();
289+  tracer .entry ("void" , this , "seeding()" );
290+ 291+  try  {
292+  StringBuilder  stringBuilder  = new  StringBuilder ();
293+  for  (int  i =0 ; i <25 ; i ++) {
294+  stringBuilder .append (this .random .nextInt (100 ));
295+  stringBuilder .append (" " );
296+  }
297+  tracer .out ().printfIndentln ("random ints = %s" , stringBuilder .toString ());
298+  } finally  {
299+  tracer .wayout ();
300+  }
301+  }
302+ 272303 @ AfterAll 
273304 void  exit () {
274305 AbstractTracer  tracer  = getCurrentTracer ();
0 commit comments