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