Skip to content

Commit ef4e495

Browse files
committed
Исправления для КА
1 parent 8eb5585 commit ef4e495

4 files changed

Lines changed: 26 additions & 15 deletions

File tree

vol8/src/main/java/ru/mifi/practice/vol8/otp/Main.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,26 @@
22

33
import ru.mifi.practice.vol8.Machine;
44

5+
import java.util.UUID;
6+
57
import static ru.mifi.practice.vol8.otp.OTPKey.CODE;
68
import static ru.mifi.practice.vol8.otp.OTPMachine.PERSISTENCE_CODE;
79

810
public abstract class Main {
911
public static void main(String[] args) {
1012
Machine machine = new OTPMachine();
1113
Machine.Context context = machine.getContext();
14+
OTPKey.MAX_SEND_CODE_ATTEMPTS.set(context, 3);
1215
Machine.State state = machine.execute();
16+
if (state.equals(OTP.WAS_SENT)) {
17+
context.set(CODE, UUID.randomUUID().toString());
18+
}
19+
state = machine.execute();
20+
if (!state.equals(OTP.FAILED_VERIFIED)) {
21+
throw new IllegalStateException();
22+
}
23+
OTPKey.RESENT.set(context, Boolean.TRUE);
24+
state = machine.execute();
1325
if (state.equals(OTP.WAS_SENT)) {
1426
context.set(CODE, context.get(PERSISTENCE_CODE, String.class).orElseThrow());
1527
}

vol8/src/main/java/ru/mifi/practice/vol8/otp/OTP.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public State next(Context context, Handler handler) {
8585
}
8686
case WAS_SENT -> {
8787
if (RESENT.is(context)) {
88+
RESENT.clear(context);
8889
return CHECK_SEND;
8990
}
9091
if (handler.isCodeEquals(context, CODE)) {
@@ -108,6 +109,7 @@ public State next(Context context, Handler handler) {
108109
}
109110
case FAILED_VERIFIED -> {
110111
if (RESENT.is(context)) {
112+
RESENT.clear(context);
111113
VERIFICATION_CODE_ATTEMPTS.clear(context);
112114
return CHECK_SEND;
113115
} else if (VERIFICATION_CODE_ATTEMPTS.isOverflow(context, MAX_VERIFICATION_CODE_ATTEMPTS)) {

vol_/src/main/java/ru/mifi/practice/voln/prime/MersenneNumbers.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ public static boolean isMersennePrime(int p) {
4949

5050
/**
5151
* Возвращает список показателей p ≤ maxP, для которых M_p — простое число.
52-
*
53-
* @param maxP верхняя граница показателя p (включительно)
54-
* @return массив показателей p
5552
*/
5653
public static int[] mersennePrimeExponentsUpTo(int maxP) {
5754
if (maxP < 2) {

vol_/src/test/java/ru/mifi/practice/voln/prime/DiffieHellmanTest.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,19 @@ void bitLengthConstructorFlow() {
4242
assertTrue(g.compareTo(BigInteger.ONE) >= 0);
4343
assertTrue(g.compareTo(p) < 0);
4444

45-
BigInteger priv1 = party1.getPrivateKey();
46-
BigInteger priv2 = party2.getPrivateKey();
47-
assertTrue(priv1.compareTo(BigInteger.ONE) >= 0);
48-
assertTrue(priv1.compareTo(p.subtract(BigInteger.ONE)) < 0);
49-
assertTrue(priv2.compareTo(BigInteger.ONE) >= 0);
50-
assertTrue(priv2.compareTo(p.subtract(BigInteger.ONE)) < 0);
45+
BigInteger privateKey1 = party1.getPrivateKey();
46+
BigInteger privateKey2 = party2.getPrivateKey();
47+
assertTrue(privateKey1.compareTo(BigInteger.ONE) >= 0);
48+
assertTrue(privateKey1.compareTo(p.subtract(BigInteger.ONE)) < 0);
49+
assertTrue(privateKey2.compareTo(BigInteger.ONE) >= 0);
50+
assertTrue(privateKey2.compareTo(p.subtract(BigInteger.ONE)) < 0);
5151

52-
BigInteger pub1 = party1.getPublicKey();
53-
BigInteger pub2 = party2.getPublicKey();
54-
assertTrue(pub1.compareTo(BigInteger.ONE) >= 0);
55-
assertTrue(pub1.compareTo(p) < 0);
56-
assertTrue(pub2.compareTo(BigInteger.ONE) >= 0);
57-
assertTrue(pub2.compareTo(p) < 0);
52+
BigInteger publicKey1 = party1.getPublicKey();
53+
BigInteger publicKey2 = party2.getPublicKey();
54+
assertTrue(publicKey1.compareTo(BigInteger.ONE) >= 0);
55+
assertTrue(publicKey1.compareTo(p) < 0);
56+
assertTrue(publicKey2.compareTo(BigInteger.ONE) >= 0);
57+
assertTrue(publicKey2.compareTo(p) < 0);
5858

5959
party1.calculateSharedSecret(party2.getPublicKey());
6060
party2.calculateSharedSecret(party1.getPublicKey());

0 commit comments

Comments
 (0)