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