1 /*
2 * GordianKnot: Security Suite
3 * Copyright 2012-2026. Tony Washer
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
6 * use this file except in compliance with the License. You may obtain a copy
7 * of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations under
15 * the License.
16 */
17 package io.github.tonywasher.joceanus.gordianknot.api.keypair;
18
19 import java.math.BigInteger;
20
21 /**
22 * Modulus Key lengths.
23 */
24 public enum GordianRSAModulus {
25 /**
26 * 2048.
27 */
28 MOD2048(2048),
29
30 /**
31 * 1024.
32 */
33 MOD1024(1024),
34
35 /**
36 * 1536.
37 */
38 MOD1536(1536),
39
40 /**
41 * 3072.
42 */
43 MOD3072(3072),
44
45 /**
46 * 4096.
47 */
48 MOD4096(4096),
49
50 /**
51 * 6144.
52 */
53 MOD6144(6144),
54
55 /**
56 * 8192.
57 */
58 MOD8192(8192);
59
60 /**
61 * The modulus length.
62 */
63 private final int theLength;
64
65 /**
66 * Constructor.
67 *
68 * @param pLength the length of the modulus
69 */
70 GordianRSAModulus(final int pLength) {
71 theLength = pLength;
72 }
73
74 /**
75 * Obtain the length of the modulus.
76 *
77 * @return the length
78 */
79 public int getLength() {
80 return theLength;
81 }
82
83 /**
84 * Obtain the modulus for a BigInteger.
85 *
86 * @param pValue the integer
87 * @return the modulus
88 */
89 public static GordianRSAModulus getModulusForInteger(final BigInteger pValue) {
90 /* Loop through the values */
91 final int myLen = pValue.bitLength();
92 for (GordianRSAModulus myModulus : values()) {
93 if (myModulus.getLength() == myLen) {
94 return myModulus;
95 }
96 }
97 return null;
98 }
99 }