35
35
*
36
36
* @author <a href="https://github.com/jchambers">Jon Chambers</a>
37
37
*/
38
- public class TimeBasedOneTimePasswordGenerator extends HmacOneTimePasswordGenerator {
38
+ public class TimeBasedOneTimePasswordGenerator {
39
+ private final HmacOneTimePasswordGenerator hotp ;
39
40
private final Duration timeStep ;
40
41
41
42
/**
@@ -115,7 +116,7 @@ public TimeBasedOneTimePasswordGenerator(final Duration timeStep, final int pass
115
116
public TimeBasedOneTimePasswordGenerator (final Duration timeStep , final int passwordLength , final String algorithm )
116
117
throws NoSuchAlgorithmRuntimeException {
117
118
118
- super (passwordLength , algorithm );
119
+ this . hotp = new HmacOneTimePasswordGenerator (passwordLength , algorithm );
119
120
this .timeStep = timeStep ;
120
121
}
121
122
@@ -131,7 +132,7 @@ public TimeBasedOneTimePasswordGenerator(final Duration timeStep, final int pass
131
132
* @throws InvalidKeyException if the given key is inappropriate for initializing the {@link Mac} for this generator
132
133
*/
133
134
public int generateOneTimePassword (final Key key , final Instant timestamp ) throws InvalidKeyException {
134
- return this .generateOneTimePassword (key , timestamp .toEpochMilli () / this .timeStep .toMillis ());
135
+ return this .hotp . generateOneTimePassword (key , timestamp .toEpochMilli () / this .timeStep .toMillis ());
135
136
}
136
137
137
138
/**
@@ -163,7 +164,7 @@ public String generateOneTimePasswordString(final Key key, final Instant timesta
163
164
* @throws InvalidKeyException if the given key is inappropriate for initializing the {@link Mac} for this generator
164
165
*/
165
166
public String generateOneTimePasswordString (final Key key , final Instant timestamp , final Locale locale ) throws InvalidKeyException {
166
- return this .formatOneTimePassword (this .generateOneTimePassword (key , timestamp ), locale );
167
+ return this .hotp . formatOneTimePassword (this .generateOneTimePassword (key , timestamp ), locale );
167
168
}
168
169
169
170
/**
@@ -174,4 +175,22 @@ public String generateOneTimePasswordString(final Key key, final Instant timesta
174
175
public Duration getTimeStep () {
175
176
return this .timeStep ;
176
177
}
178
+
179
+ /**
180
+ * Returns the length, in decimal digits, of passwords produced by this generator.
181
+ *
182
+ * @return the length, in decimal digits, of passwords produced by this generator
183
+ */
184
+ public int getPasswordLength () {
185
+ return this .hotp .getPasswordLength ();
186
+ }
187
+
188
+ /**
189
+ * Returns the name of the HMAC algorithm used by this generator.
190
+ *
191
+ * @return the name of the HMAC algorithm used by this generator
192
+ */
193
+ public String getAlgorithm () {
194
+ return this .hotp .getAlgorithm ();
195
+ }
177
196
}
0 commit comments