diff --git a/MasterPassword/Java/masterpassword-algorithm/pom.xml b/MasterPassword/Java/masterpassword-algorithm/pom.xml index 0ea494d3..ea6ecebb 100644 --- a/MasterPassword/Java/masterpassword-algorithm/pom.xml +++ b/MasterPassword/Java/masterpassword-algorithm/pom.xml @@ -13,7 +13,6 @@ Master Password Algorithm Implementation The implementation of the Master Password algorithm - com.lyndir.masterpassword masterpassword-algorithm jar diff --git a/MasterPassword/Java/masterpassword-algorithm/src/main/java/com/lyndir/masterpassword/MPSiteType.java b/MasterPassword/Java/masterpassword-algorithm/src/main/java/com/lyndir/masterpassword/MPSiteType.java index f78d2a44..10eb56bc 100644 --- a/MasterPassword/Java/masterpassword-algorithm/src/main/java/com/lyndir/masterpassword/MPSiteType.java +++ b/MasterPassword/Java/masterpassword-algorithm/src/main/java/com/lyndir/masterpassword/MPSiteType.java @@ -147,7 +147,7 @@ public enum MPSiteType { * * @return The type registered with the given name. */ - public static MPSiteType forName(final String name) { + public static MPSiteType forName(@Nullable final String name) { if (name == null) return null; diff --git a/MasterPassword/Java/masterpassword-algorithm/src/main/java/com/lyndir/masterpassword/MPSiteVariant.java b/MasterPassword/Java/masterpassword-algorithm/src/main/java/com/lyndir/masterpassword/MPSiteVariant.java index f87f32cd..45213857 100644 --- a/MasterPassword/Java/masterpassword-algorithm/src/main/java/com/lyndir/masterpassword/MPSiteVariant.java +++ b/MasterPassword/Java/masterpassword-algorithm/src/main/java/com/lyndir/masterpassword/MPSiteVariant.java @@ -3,6 +3,7 @@ package com.lyndir.masterpassword; import com.google.common.collect.ImmutableList; import com.lyndir.lhunath.opal.system.logging.Logger; import java.util.List; +import javax.annotation.Nullable; /** @@ -65,7 +66,7 @@ public enum MPSiteVariant { * * @return The variant registered with the given name. */ - public static MPSiteVariant forName(final String name) { + public static MPSiteVariant forName(@Nullable final String name) { if (name == null) return null; diff --git a/MasterPassword/Java/masterpassword-algorithm/src/main/java/com/lyndir/masterpassword/MPTemplate.java b/MasterPassword/Java/masterpassword-algorithm/src/main/java/com/lyndir/masterpassword/MPTemplate.java index 6a7c3d8d..b605ccab 100644 --- a/MasterPassword/Java/masterpassword-algorithm/src/main/java/com/lyndir/masterpassword/MPTemplate.java +++ b/MasterPassword/Java/masterpassword-algorithm/src/main/java/com/lyndir/masterpassword/MPTemplate.java @@ -3,10 +3,8 @@ package com.lyndir.masterpassword; import static com.lyndir.lhunath.opal.system.util.StringUtils.strf; import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; import com.lyndir.lhunath.opal.system.util.MetaObject; import java.util.List; -import java.util.Map; /** diff --git a/MasterPassword/Java/masterpassword-algorithm/src/main/java/com/lyndir/masterpassword/MPTemplateCharacterClass.java b/MasterPassword/Java/masterpassword-algorithm/src/main/java/com/lyndir/masterpassword/MPTemplateCharacterClass.java index 2838034f..54aa04cb 100644 --- a/MasterPassword/Java/masterpassword-algorithm/src/main/java/com/lyndir/masterpassword/MPTemplateCharacterClass.java +++ b/MasterPassword/Java/masterpassword-algorithm/src/main/java/com/lyndir/masterpassword/MPTemplateCharacterClass.java @@ -1,8 +1,6 @@ package com.lyndir.masterpassword; import com.lyndir.lhunath.opal.system.logging.Logger; -import com.lyndir.lhunath.opal.system.util.MetaObject; -import com.lyndir.lhunath.opal.system.util.ObjectMeta; /** 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 886063e0..84390db9 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 @@ -54,7 +54,7 @@ public abstract class MasterKey { @Nullable protected abstract byte[] deriveKey(final char[] masterPassword); - protected abstract Version getAlgorithm(); + public abstract Version getAlgorithmVersion(); @NotNull public String getFullName() { @@ -63,18 +63,18 @@ public abstract class MasterKey { } @Nonnull - protected byte[] getMasterKey() { + protected byte[] getKey() { return Preconditions.checkNotNull( masterKey ); } public byte[] getKeyID() { - return idForBytes( getMasterKey() ); + return idForBytes( getKey() ); } - public abstract String encode(@Nonnull final String siteName, final MPSiteType siteType, int siteCounter, final MPSiteVariant siteVariant, - @Nullable final String siteContext); + public abstract String encode(@Nonnull final String siteName, final MPSiteType siteType, int siteCounter, + final MPSiteVariant siteVariant, @Nullable final String siteContext); public boolean isValid() { return masterKey != null; @@ -95,8 +95,12 @@ public abstract class MasterKey { long start = System.currentTimeMillis(); masterKey = deriveKey( masterPassword ); - logger.trc( "masterKey ID: %s (derived in %.2fs)", CodeUtils.encodeHex( idForBytes( masterKey ) ), - (System.currentTimeMillis() - start) / 1000D ); + + if (masterKey == null) + logger.dbg( "masterKey calculation failed after %.2fs.", (System.currentTimeMillis() - start) / 1000D ); + else + logger.trc( "masterKey ID: %s (derived in %.2fs)", CodeUtils.encodeHex( idForBytes( masterKey ) ), + (System.currentTimeMillis() - start) / 1000D ); return this; } diff --git a/MasterPassword/Java/masterpassword-algorithm/src/main/java/com/lyndir/masterpassword/MasterKeyV0.java b/MasterPassword/Java/masterpassword-algorithm/src/main/java/com/lyndir/masterpassword/MasterKeyV0.java index 040db693..c5061be8 100644 --- a/MasterPassword/Java/masterpassword-algorithm/src/main/java/com/lyndir/masterpassword/MasterKeyV0.java +++ b/MasterPassword/Java/masterpassword-algorithm/src/main/java/com/lyndir/masterpassword/MasterKeyV0.java @@ -41,7 +41,7 @@ public class MasterKeyV0 extends MasterKey { } @Override - protected Version getAlgorithm() { + public Version getAlgorithmVersion() { return Version.V0; } @@ -101,7 +101,7 @@ public class MasterKeyV0 extends MasterKey { sitePasswordInfo = Bytes.concat( sitePasswordInfo, siteContextLengthBytes, siteContextBytes ); logger.trc( "sitePasswordInfo ID: %s", CodeUtils.encodeHex( idForBytes( sitePasswordInfo ) ) ); - byte[] sitePasswordSeed = MP_mac.of( getMasterKey(), sitePasswordInfo ); + byte[] sitePasswordSeed = MP_mac.of( getKey(), sitePasswordInfo ); logger.trc( "sitePasswordSeed ID: %s", CodeUtils.encodeHex( idForBytes( sitePasswordSeed ) ) ); Preconditions.checkState( sitePasswordSeed.length > 0 ); diff --git a/MasterPassword/Java/masterpassword-algorithm/src/main/java/com/lyndir/masterpassword/MasterKeyV1.java b/MasterPassword/Java/masterpassword-algorithm/src/main/java/com/lyndir/masterpassword/MasterKeyV1.java index 6889863e..2d1abb62 100644 --- a/MasterPassword/Java/masterpassword-algorithm/src/main/java/com/lyndir/masterpassword/MasterKeyV1.java +++ b/MasterPassword/Java/masterpassword-algorithm/src/main/java/com/lyndir/masterpassword/MasterKeyV1.java @@ -1,15 +1,9 @@ package com.lyndir.masterpassword; -import com.google.common.base.Charsets; import com.google.common.base.Preconditions; import com.google.common.primitives.Bytes; -import com.lambdaworks.crypto.SCrypt; import com.lyndir.lhunath.opal.system.*; import com.lyndir.lhunath.opal.system.logging.Logger; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.nio.charset.Charset; -import java.security.GeneralSecurityException; import javax.annotation.Nullable; @@ -30,7 +24,7 @@ public class MasterKeyV1 extends MasterKeyV0 { } @Override - protected Version getAlgorithm() { + public Version getAlgorithmVersion() { return Version.V1; } @@ -64,7 +58,7 @@ public class MasterKeyV1 extends MasterKeyV0 { sitePasswordInfo = Bytes.concat( sitePasswordInfo, siteContextLengthBytes, siteContextBytes ); logger.trc( "sitePasswordInfo ID: %s", CodeUtils.encodeHex( idForBytes( sitePasswordInfo ) ) ); - byte[] sitePasswordSeed = MP_mac.of( getMasterKey(), sitePasswordInfo ); + byte[] sitePasswordSeed = MP_mac.of( getKey(), sitePasswordInfo ); logger.trc( "sitePasswordSeed ID: %s", CodeUtils.encodeHex( idForBytes( sitePasswordSeed ) ) ); Preconditions.checkState( sitePasswordSeed.length > 0 ); diff --git a/MasterPassword/Java/masterpassword-algorithm/src/main/java/com/lyndir/masterpassword/MasterKeyV2.java b/MasterPassword/Java/masterpassword-algorithm/src/main/java/com/lyndir/masterpassword/MasterKeyV2.java index 5ebc0012..9b4945d9 100644 --- a/MasterPassword/Java/masterpassword-algorithm/src/main/java/com/lyndir/masterpassword/MasterKeyV2.java +++ b/MasterPassword/Java/masterpassword-algorithm/src/main/java/com/lyndir/masterpassword/MasterKeyV2.java @@ -23,7 +23,7 @@ public class MasterKeyV2 extends MasterKeyV1 { } @Override - protected Version getAlgorithm() { + public Version getAlgorithmVersion() { return Version.V2; } @@ -57,7 +57,7 @@ public class MasterKeyV2 extends MasterKeyV1 { sitePasswordInfo = Bytes.concat( sitePasswordInfo, siteContextLengthBytes, siteContextBytes ); logger.trc( "sitePasswordInfo ID: %s", CodeUtils.encodeHex( idForBytes( sitePasswordInfo ) ) ); - byte[] sitePasswordSeed = MP_mac.of( getMasterKey(), sitePasswordInfo ); + byte[] sitePasswordSeed = MP_mac.of( getKey(), sitePasswordInfo ); logger.trc( "sitePasswordSeed ID: %s", CodeUtils.encodeHex( idForBytes( sitePasswordSeed ) ) ); Preconditions.checkState( sitePasswordSeed.length > 0 ); diff --git a/MasterPassword/Java/masterpassword-algorithm/src/main/java/com/lyndir/masterpassword/MasterKeyV3.java b/MasterPassword/Java/masterpassword-algorithm/src/main/java/com/lyndir/masterpassword/MasterKeyV3.java index 0c9cfc6b..7d593f1e 100644 --- a/MasterPassword/Java/masterpassword-algorithm/src/main/java/com/lyndir/masterpassword/MasterKeyV3.java +++ b/MasterPassword/Java/masterpassword-algorithm/src/main/java/com/lyndir/masterpassword/MasterKeyV3.java @@ -26,7 +26,7 @@ public class MasterKeyV3 extends MasterKeyV2 { } @Override - protected Version getAlgorithm() { + public Version getAlgorithmVersion() { return Version.V3; } 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 de9b804e..db908d09 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 @@ -149,7 +149,7 @@ public class MPWTests { } public char[] getMasterPassword() { - return masterPassword.toCharArray(); + return masterPassword == null? null: masterPassword.toCharArray(); } public String getKeyID() { @@ -161,7 +161,7 @@ public class MPWTests { } public int getSiteCounter() { - return siteCounter; + return ifNotNullElse( siteCounter, 1 ); } public MPSiteType getSiteType() { diff --git a/MasterPassword/Java/masterpassword-android/pom.xml b/MasterPassword/Java/masterpassword-android/pom.xml index 075a4d80..a44f5ee1 100644 --- a/MasterPassword/Java/masterpassword-android/pom.xml +++ b/MasterPassword/Java/masterpassword-android/pom.xml @@ -13,13 +13,19 @@ Master Password Android An Android application to the Master Password algorithm - com.lyndir.masterpassword masterpassword-android apk + + org.codehaus.mojo + buildnumber-maven-plugin + + YYYYMMddHHmm + + com.jayway.maven.plugins.android.generation2 android-maven-plugin @@ -30,9 +36,23 @@ false - 19 + 21 + + + + manifest-merger + process-resources + + manifest-update + + + ${timestamp} + ${project.version} + + + diff --git a/MasterPassword/Java/masterpassword-android/res/layout/activity_users.xml b/MasterPassword/Java/masterpassword-android/res/layout/activity_users.xml index 91922ec3..baca123d 100644 --- a/MasterPassword/Java/masterpassword-android/res/layout/activity_users.xml +++ b/MasterPassword/Java/masterpassword-android/res/layout/activity_users.xml @@ -1,36 +1,30 @@ - + - + + + + android:layout_height="wrap_content" + android:divider="@drawable/divider20" + android:showDividers="middle" /> - - - - - - - - + + + diff --git a/MasterPassword/Java/masterpassword-android/src/main/java/com/lyndir/masterpassword/EmergencyActivity.java b/MasterPassword/Java/masterpassword-android/src/main/java/com/lyndir/masterpassword/EmergencyActivity.java index 170ff6b6..939af580 100644 --- a/MasterPassword/Java/masterpassword-android/src/main/java/com/lyndir/masterpassword/EmergencyActivity.java +++ b/MasterPassword/Java/masterpassword-android/src/main/java/com/lyndir/masterpassword/EmergencyActivity.java @@ -205,7 +205,7 @@ public class EmergencyActivity extends Activity { final MasterKey.Version version = (MasterKey.Version) siteVersionField.getSelectedItem(); try { if (fullName.hashCode() == hc_userName && Arrays.hashCode( masterPassword ) == hc_masterPassword && - masterKeyFuture != null && masterKeyFuture.get().getAlgorithm() == version) + masterKeyFuture != null && masterKeyFuture.get().getAlgorithmVersion() == version) return; } catch (InterruptedException | ExecutionException e) { diff --git a/MasterPassword/Java/masterpassword-android/src/main/java/com/lyndir/masterpassword/Res.java b/MasterPassword/Java/masterpassword-android/src/main/java/com/lyndir/masterpassword/Res.java index 0f8824e7..5ac37a42 100644 --- a/MasterPassword/Java/masterpassword-android/src/main/java/com/lyndir/masterpassword/Res.java +++ b/MasterPassword/Java/masterpassword-android/src/main/java/com/lyndir/masterpassword/Res.java @@ -1,7 +1,6 @@ package com.lyndir.masterpassword; import android.content.res.Resources; -import android.graphics.Paint; import android.graphics.Typeface; diff --git a/MasterPassword/Java/masterpassword-android/src/main/java/com/lyndir/masterpassword/model/User.java b/MasterPassword/Java/masterpassword-android/src/main/java/com/lyndir/masterpassword/model/User.java index 9568f9fc..88035027 100644 --- a/MasterPassword/Java/masterpassword-android/src/main/java/com/lyndir/masterpassword/model/User.java +++ b/MasterPassword/Java/masterpassword-android/src/main/java/com/lyndir/masterpassword/model/User.java @@ -2,16 +2,14 @@ package com.lyndir.masterpassword.model; import static com.lyndir.lhunath.opal.system.util.StringUtils.strf; -import java.util.Objects; - /** * @author lhunath, 2014-08-20 */ public class User { - private String name; - private Avatar avatar; + private final String name; + private final Avatar avatar; public User(final String name, final Avatar avatar) { this.name = name; diff --git a/MasterPassword/Java/masterpassword-cli/pom.xml b/MasterPassword/Java/masterpassword-cli/pom.xml index 93f99018..c0df5306 100644 --- a/MasterPassword/Java/masterpassword-cli/pom.xml +++ b/MasterPassword/Java/masterpassword-cli/pom.xml @@ -13,7 +13,6 @@ Master Password CLI A CLI interface to the Master Password algorithm - com.lyndir.masterpassword masterpassword-cli jar diff --git a/MasterPassword/Java/masterpassword-cli/src/main/java/com/lyndir/masterpassword/CLI.java b/MasterPassword/Java/masterpassword-cli/src/main/java/com/lyndir/masterpassword/CLI.java index 94944564..b818c988 100644 --- a/MasterPassword/Java/masterpassword-cli/src/main/java/com/lyndir/masterpassword/CLI.java +++ b/MasterPassword/Java/masterpassword-cli/src/main/java/com/lyndir/masterpassword/CLI.java @@ -45,7 +45,7 @@ public class CLI { throws IOException { // Read information from the environment. - char[] masterPassword = null; + char[] masterPassword; String siteName = null, context = null; String userName = System.getenv( ENV_USERNAME ); String siteTypeName = ifNotNullElse( System.getenv( ENV_SITETYPE ), "" ); diff --git a/MasterPassword/Java/masterpassword-gui/pom.xml b/MasterPassword/Java/masterpassword-gui/pom.xml index 63aab06a..53e86e52 100644 --- a/MasterPassword/Java/masterpassword-gui/pom.xml +++ b/MasterPassword/Java/masterpassword-gui/pom.xml @@ -13,7 +13,6 @@ Master Password GUI A GUI interface to the Master Password algorithm - com.lyndir.masterpassword masterpassword-gui jar diff --git a/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/GUI.java b/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/GUI.java index 2e985d19..f5eefe44 100644 --- a/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/GUI.java +++ b/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/GUI.java @@ -21,8 +21,6 @@ import com.google.common.base.Charsets; import com.google.common.io.*; import com.lyndir.lhunath.opal.system.logging.Logger; import com.lyndir.lhunath.opal.system.util.TypeUtils; -import com.lyndir.masterpassword.MasterKey; -import com.lyndir.masterpassword.model.IncorrectMasterPasswordException; import java.io.*; import java.net.URI; import java.net.URL; @@ -41,7 +39,7 @@ public class GUI implements UnlockFrame.SignInCallback { @SuppressWarnings("UnusedDeclaration") private static final Logger logger = Logger.get( GUI.class ); - private UnlockFrame unlockFrame = new UnlockFrame( this ); + private final UnlockFrame unlockFrame = new UnlockFrame( this ); private PasswordFrame passwordFrame; public static void main(final String[] args) diff --git a/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/ModelAuthenticationPanel.java b/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/ModelAuthenticationPanel.java index dbd9d4a4..56037f9e 100644 --- a/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/ModelAuthenticationPanel.java +++ b/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/ModelAuthenticationPanel.java @@ -1,6 +1,7 @@ package com.lyndir.masterpassword.gui; import com.google.common.base.Function; +import com.google.common.base.Preconditions; import com.google.common.collect.*; import com.lyndir.lhunath.opal.system.logging.Logger; import com.lyndir.masterpassword.model.MPUser; @@ -137,8 +138,8 @@ public class ModelAuthenticationPanel extends AuthenticationPanel implements Ite return FluentIterable.from( MPUserFileManager.get().getUsers() ).transform( new Function() { @Nullable @Override - public ModelUser apply(final MPUser model) { - return new ModelUser( model ); + public ModelUser apply(@Nullable final MPUser model) { + return new ModelUser( Preconditions.checkNotNull( model ) ); } } ).toArray( ModelUser.class ); } diff --git a/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/ModelUser.java b/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/ModelUser.java index 8523d485..d2009c6e 100644 --- a/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/ModelUser.java +++ b/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/ModelUser.java @@ -48,7 +48,7 @@ public class ModelUser extends User { public void authenticate(final char[] masterPassword) throws IncorrectMasterPasswordException { - model.authenticate( masterPassword ); + putKey( model.authenticate( masterPassword ) ); this.masterPassword = masterPassword; } @@ -81,6 +81,7 @@ public class ModelUser extends User { } public boolean keySaved() { + // TODO return false; } } diff --git a/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/User.java b/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/User.java index 8dc73287..0f62e3d3 100644 --- a/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/User.java +++ b/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/User.java @@ -1,7 +1,6 @@ package com.lyndir.masterpassword.gui; -import static com.lyndir.lhunath.opal.system.util.StringUtils.*; - +import com.google.common.base.Preconditions; import com.google.common.collect.Maps; import com.lyndir.masterpassword.MasterKey; import com.lyndir.masterpassword.model.IncorrectMasterPasswordException; @@ -17,7 +16,7 @@ import javax.annotation.Nullable; public abstract class User { @Nonnull - private static final EnumMap keyByVersion = Maps.newEnumMap( MasterKey.Version.class ); + private final EnumMap keyByVersion = Maps.newEnumMap( MasterKey.Version.class ); public abstract String getFullName(); @@ -37,17 +36,23 @@ public abstract class User { @Nonnull public MasterKey getKey(MasterKey.Version algorithmVersion) { - char[] masterPassword = getMasterPassword(); + char[] masterPassword = Preconditions.checkNotNull( getMasterPassword(), "User is not authenticated: " + getFullName() ); MasterKey key = keyByVersion.get( algorithmVersion ); if (key == null) - keyByVersion.put( algorithmVersion, key = MasterKey.create( algorithmVersion, getFullName(), masterPassword ) ); + putKey( key = MasterKey.create( algorithmVersion, getFullName(), masterPassword ) ); if (!key.isValid()) key.revalidate( masterPassword ); return key; } + protected void putKey(MasterKey masterKey) { + MasterKey oldKey = keyByVersion.put( masterKey.getAlgorithmVersion(), masterKey ); + if (oldKey != null) + oldKey.invalidate(); + } + public void reset() { for (MasterKey key : keyByVersion.values()) key.invalidate(); diff --git a/MasterPassword/Java/masterpassword-model/pom.xml b/MasterPassword/Java/masterpassword-model/pom.xml index 395424a0..34ec8ae2 100644 --- a/MasterPassword/Java/masterpassword-model/pom.xml +++ b/MasterPassword/Java/masterpassword-model/pom.xml @@ -13,7 +13,6 @@ Master Password Site Model A persistence model for Master Password sites. - com.lyndir.masterpassword masterpassword-model jar diff --git a/MasterPassword/Java/masterpassword-model/src/main/java/com/lyndir/masterpassword/model/MPSite.java b/MasterPassword/Java/masterpassword-model/src/main/java/com/lyndir/masterpassword/model/MPSite.java index 6e9d880a..71d8edb2 100644 --- a/MasterPassword/Java/masterpassword-model/src/main/java/com/lyndir/masterpassword/model/MPSite.java +++ b/MasterPassword/Java/masterpassword-model/src/main/java/com/lyndir/masterpassword/model/MPSite.java @@ -1,6 +1,5 @@ package com.lyndir.masterpassword.model; -import static com.lyndir.lhunath.opal.system.util.ObjectUtils.ifNotNullElse; import static com.lyndir.lhunath.opal.system.util.StringUtils.strf; import com.lyndir.masterpassword.*; @@ -56,7 +55,7 @@ public class MPSite { return resultFor( masterKey, MPSiteVariant.Password, null ); } - public String resultFor(final MasterKey masterKey, final MPSiteVariant variant, final String context) { + public String resultFor(final MasterKey masterKey, final MPSiteVariant variant, @Nullable final String context) { return masterKey.encode( siteName, siteType, siteCounter, variant, context ); } diff --git a/MasterPassword/Java/masterpassword-model/src/main/java/com/lyndir/masterpassword/model/MPSiteMarshaller.java b/MasterPassword/Java/masterpassword-model/src/main/java/com/lyndir/masterpassword/model/MPSiteMarshaller.java index babfb40d..c6ff7740 100644 --- a/MasterPassword/Java/masterpassword-model/src/main/java/com/lyndir/masterpassword/model/MPSiteMarshaller.java +++ b/MasterPassword/Java/masterpassword-model/src/main/java/com/lyndir/masterpassword/model/MPSiteMarshaller.java @@ -4,7 +4,6 @@ import static com.lyndir.lhunath.opal.system.util.ObjectUtils.ifNotNullElse; import static com.lyndir.lhunath.opal.system.util.StringUtils.strf; import com.google.common.base.Preconditions; -import com.lyndir.lhunath.opal.system.CodeUtils; import com.lyndir.masterpassword.MasterKey; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -51,11 +50,12 @@ public class MPSiteMarshaller { } private String marshallHeader(final ContentMode contentMode, final MPUser user, @Nullable final MasterKey masterKey) { + this.contentMode = contentMode; this.masterKey = masterKey; StringBuilder header = new StringBuilder(); header.append( "# Master Password site export\n" ); - header.append( "# " ).append( contentMode.description() ).append( '\n' ); + header.append( "# " ).append( this.contentMode.description() ).append( '\n' ); header.append( "# \n" ); header.append( "##\n" ); header.append( "# Format: 1\n" ); @@ -67,7 +67,7 @@ public class MPSiteMarshaller { header.append( "# Version: " ).append( MasterKey.Version.CURRENT.toBundleVersion() ).append( '\n' ); header.append( "# Algorithm: " ).append( MasterKey.Version.CURRENT.toInt() ).append( '\n' ); header.append( "# Default Type: " ).append( user.getDefaultType().getType() ).append( '\n' ); - header.append( "# Passwords: " ).append( contentMode.name() ).append( '\n' ); + header.append( "# Passwords: " ).append( this.contentMode.name() ).append( '\n' ); header.append( "##\n" ); header.append( "#\n" ); header.append( "# Last Times Password Login\t Site\tSite\n" ); diff --git a/MasterPassword/Java/masterpassword-model/src/main/java/com/lyndir/masterpassword/model/MPUser.java b/MasterPassword/Java/masterpassword-model/src/main/java/com/lyndir/masterpassword/model/MPUser.java index f90ca391..fac7d8a2 100644 --- a/MasterPassword/Java/masterpassword-model/src/main/java/com/lyndir/masterpassword/model/MPUser.java +++ b/MasterPassword/Java/masterpassword-model/src/main/java/com/lyndir/masterpassword/model/MPUser.java @@ -22,11 +22,11 @@ public class MPUser implements Comparable { private final Collection sites = Sets.newHashSet(); @Nullable - private byte[] keyID; - private MasterKey.Version algorithmVersion; - private int avatar; - private MPSiteType defaultType; - private ReadableInstant lastUsed; + private byte[] keyID; + private final MasterKey.Version algorithmVersion; + private int avatar; + private MPSiteType defaultType; + private ReadableInstant lastUsed; public MPUser(final String fullName) { this( fullName, null ); diff --git a/MasterPassword/Java/masterpassword-model/src/main/java/com/lyndir/masterpassword/model/MPUserFileManager.java b/MasterPassword/Java/masterpassword-model/src/main/java/com/lyndir/masterpassword/model/MPUserFileManager.java index 7c0a1674..d3c5b749 100644 --- a/MasterPassword/Java/masterpassword-model/src/main/java/com/lyndir/masterpassword/model/MPUserFileManager.java +++ b/MasterPassword/Java/masterpassword-model/src/main/java/com/lyndir/masterpassword/model/MPUserFileManager.java @@ -58,9 +58,9 @@ public class MPUserFileManager extends MPUserManager { } ) ) ).transform( new Function() { @Nullable @Override - public MPUser apply(final File file) { + public MPUser apply(@Nullable final File file) { try { - return MPSiteUnmarshaller.unmarshall( file ).getUser(); + return MPSiteUnmarshaller.unmarshall( Preconditions.checkNotNull( file ) ).getUser(); } catch (IOException e) { logger.err( e, "Couldn't read user from: %s", file ); diff --git a/MasterPassword/Java/masterpassword-model/src/main/java/com/lyndir/masterpassword/model/MPUserManager.java b/MasterPassword/Java/masterpassword-model/src/main/java/com/lyndir/masterpassword/model/MPUserManager.java index 8c59763a..807d727c 100644 --- a/MasterPassword/Java/masterpassword-model/src/main/java/com/lyndir/masterpassword/model/MPUserManager.java +++ b/MasterPassword/Java/masterpassword-model/src/main/java/com/lyndir/masterpassword/model/MPUserManager.java @@ -16,7 +16,7 @@ public abstract class MPUserManager { return instance; } - public MPUserManager(final Iterable users) { + protected MPUserManager(final Iterable users) { for (MPUser user : users) addUser( user ); }