1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty5.handler.ssl.util;
17
18 import java.security.SecureRandom;
19 import java.util.Random;
20 import java.util.concurrent.ThreadLocalRandom;
21
22
23
24
25
26 final class ThreadLocalInsecureRandom extends SecureRandom {
27
28 private static final long serialVersionUID = -8209473337192526191L;
29
30 private static final SecureRandom INSTANCE = new ThreadLocalInsecureRandom();
31
32 static SecureRandom current() {
33 return INSTANCE;
34 }
35
36 private ThreadLocalInsecureRandom() { }
37
38 @Override
39 public String getAlgorithm() {
40 return "insecure";
41 }
42
43 @Override
44 public void setSeed(byte[] seed) { }
45
46 @Override
47 public void setSeed(long seed) { }
48
49 @Override
50 public void nextBytes(byte[] bytes) {
51 random().nextBytes(bytes);
52 }
53
54 @Override
55 public byte[] generateSeed(int numBytes) {
56 byte[] seed = new byte[numBytes];
57 random().nextBytes(seed);
58 return seed;
59 }
60
61 @Override
62 public int nextInt() {
63 return random().nextInt();
64 }
65
66 @Override
67 public int nextInt(int n) {
68 return random().nextInt(n);
69 }
70
71 @Override
72 public boolean nextBoolean() {
73 return random().nextBoolean();
74 }
75
76 @Override
77 public long nextLong() {
78 return random().nextLong();
79 }
80
81 @Override
82 public float nextFloat() {
83 return random().nextFloat();
84 }
85
86 @Override
87 public double nextDouble() {
88 return random().nextDouble();
89 }
90
91 @Override
92 public double nextGaussian() {
93 return random().nextGaussian();
94 }
95
96 private static Random random() {
97 return ThreadLocalRandom.current();
98 }
99 }