From 0fdf894bf08e2a0f2c547710fa4090397bcae972 Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Fri, 12 Dec 2014 10:54:28 -0500 Subject: [PATCH] Fix issue with passing context in Java algorithm and test case. --- .../main/java/com/lyndir/masterpassword/MasterKey.java | 2 ++ .../test/java/com/lyndir/masterpassword/MPWTests.java | 3 ++- .../java/com/lyndir/masterpassword/MasterKeyTest.java | 9 +++++---- .../src/test/resources/mpw_tests.xml | 1 - 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/MasterPassword/Java/masterpassword-algorithm/src/main/java/com/lyndir/masterpassword/MasterKey.java b/MasterPassword/Java/masterpassword-algorithm/src/main/java/com/lyndir/masterpassword/MasterKey.java index a13ed702..a1013c1c 100644 --- a/MasterPassword/Java/masterpassword-algorithm/src/main/java/com/lyndir/masterpassword/MasterKey.java +++ b/MasterPassword/Java/masterpassword-algorithm/src/main/java/com/lyndir/masterpassword/MasterKey.java @@ -112,6 +112,8 @@ public class MasterKey { siteContext == null? "(null)": siteContext ); byte[] sitePasswordInfo = Bytes.concat( siteScope.getBytes( MP_charset ), siteNameLengthBytes, siteNameBytes, siteCounterBytes ); + if (siteContextBytes != null) + sitePasswordInfo = Bytes.concat( sitePasswordInfo, siteContextLengthBytes, siteContextBytes ); logger.trc( "sitePasswordInfo ID: %s", CodeUtils.encodeHex( idForBytes( sitePasswordInfo ) ) ); byte[] sitePasswordSeed = MP_mac.of( masterKey, sitePasswordInfo ); diff --git a/MasterPassword/Java/masterpassword-algorithm/src/test/java/com/lyndir/masterpassword/MPWTests.java b/MasterPassword/Java/masterpassword-algorithm/src/test/java/com/lyndir/masterpassword/MPWTests.java index a77ba0ca..bcd145f9 100644 --- a/MasterPassword/Java/masterpassword-algorithm/src/test/java/com/lyndir/masterpassword/MPWTests.java +++ b/MasterPassword/Java/masterpassword-algorithm/src/test/java/com/lyndir/masterpassword/MPWTests.java @@ -4,6 +4,7 @@ import static com.lyndir.lhunath.opal.system.util.ObjectUtils.*; import com.lyndir.lhunath.opal.system.logging.Logger; import com.lyndir.lhunath.opal.system.util.NNSupplier; +import com.lyndir.lhunath.opal.system.util.NSupplier; import java.util.List; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -117,7 +118,7 @@ public class MPWTests { return parentCase.getSiteVariant().name(); } } ); - siteContext = ifNotNullElse( siteContext, new NNSupplier() { + siteContext = ifNotNullElseNullable( siteContext, new NSupplier() { @Nonnull @Override public String get() { diff --git a/MasterPassword/Java/masterpassword-algorithm/src/test/java/com/lyndir/masterpassword/MasterKeyTest.java b/MasterPassword/Java/masterpassword-algorithm/src/test/java/com/lyndir/masterpassword/MasterKeyTest.java index 2758c01f..523dc44b 100644 --- a/MasterPassword/Java/masterpassword-algorithm/src/test/java/com/lyndir/masterpassword/MasterKeyTest.java +++ b/MasterPassword/Java/masterpassword-algorithm/src/test/java/com/lyndir/masterpassword/MasterKeyTest.java @@ -3,6 +3,7 @@ package com.lyndir.masterpassword; import static org.testng.Assert.*; import com.google.common.io.Resources; +import com.lyndir.lhunath.opal.system.CodeUtils; import com.lyndir.lhunath.opal.system.logging.Logger; import java.net.URL; import javax.xml.bind.JAXBContext; @@ -35,9 +36,9 @@ public class MasterKeyTest { for (MPWTests.Case testCase : tests.getCases()) { MasterKey masterKey = new MasterKey( testCase.getFullName(), testCase.getMasterPassword() ); - assertEquals( masterKey.encode( testCase.getSiteName(), testCase.getSiteType(), testCase.getSiteCounter(), - testCase.getSiteVariant(), testCase.getSiteContext() ), testCase.getResult(), - "Failed test case: " + testCase ); + assertEquals( + masterKey.encode( testCase.getSiteName(), testCase.getSiteType(), testCase.getSiteCounter(), testCase.getSiteVariant(), + testCase.getSiteContext() ), testCase.getResult(), "Failed test case: " + testCase ); } } @@ -55,7 +56,7 @@ public class MasterKeyTest { for (MPWTests.Case testCase : tests.getCases()) { MasterKey masterKey = new MasterKey( testCase.getFullName(), testCase.getMasterPassword() ); - assertEquals( masterKey.getKeyID(), testCase.getKeyID(), "Failed test case: " + testCase ); + assertEquals( CodeUtils.encodeHex( masterKey.getKeyID() ), testCase.getKeyID(), "Failed test case: " + testCase ); } } diff --git a/MasterPassword/Java/masterpassword-algorithm/src/test/resources/mpw_tests.xml b/MasterPassword/Java/masterpassword-algorithm/src/test/resources/mpw_tests.xml index b5d4e41f..09ca5a21 100644 --- a/MasterPassword/Java/masterpassword-algorithm/src/test/resources/mpw_tests.xml +++ b/MasterPassword/Java/masterpassword-algorithm/src/test/resources/mpw_tests.xml @@ -7,7 +7,6 @@ 1 GeneratedLong Password - Jejr5[RepuSosp