2
0

Some generic code fix-ups throughout.

This commit is contained in:
Maarten Billemont 2015-02-05 13:14:17 -05:00
parent 145008406d
commit b84ae532f2
29 changed files with 100 additions and 94 deletions

View File

@ -13,7 +13,6 @@
<name>Master Password Algorithm Implementation</name> <name>Master Password Algorithm Implementation</name>
<description>The implementation of the Master Password algorithm</description> <description>The implementation of the Master Password algorithm</description>
<groupId>com.lyndir.masterpassword</groupId>
<artifactId>masterpassword-algorithm</artifactId> <artifactId>masterpassword-algorithm</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>

View File

@ -147,7 +147,7 @@ public enum MPSiteType {
* *
* @return The type registered with the given name. * @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) if (name == null)
return null; return null;

View File

@ -3,6 +3,7 @@ package com.lyndir.masterpassword;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.lyndir.lhunath.opal.system.logging.Logger; import com.lyndir.lhunath.opal.system.logging.Logger;
import java.util.List; import java.util.List;
import javax.annotation.Nullable;
/** /**
@ -65,7 +66,7 @@ public enum MPSiteVariant {
* *
* @return The variant registered with the given name. * @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) if (name == null)
return null; return null;

View File

@ -3,10 +3,8 @@ package com.lyndir.masterpassword;
import static com.lyndir.lhunath.opal.system.util.StringUtils.strf; import static com.lyndir.lhunath.opal.system.util.StringUtils.strf;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.lyndir.lhunath.opal.system.util.MetaObject; import com.lyndir.lhunath.opal.system.util.MetaObject;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**

View File

@ -1,8 +1,6 @@
package com.lyndir.masterpassword; package com.lyndir.masterpassword;
import com.lyndir.lhunath.opal.system.logging.Logger; import com.lyndir.lhunath.opal.system.logging.Logger;
import com.lyndir.lhunath.opal.system.util.MetaObject;
import com.lyndir.lhunath.opal.system.util.ObjectMeta;
/** /**

View File

@ -54,7 +54,7 @@ public abstract class MasterKey {
@Nullable @Nullable
protected abstract byte[] deriveKey(final char[] masterPassword); protected abstract byte[] deriveKey(final char[] masterPassword);
protected abstract Version getAlgorithm(); public abstract Version getAlgorithmVersion();
@NotNull @NotNull
public String getFullName() { public String getFullName() {
@ -63,18 +63,18 @@ public abstract class MasterKey {
} }
@Nonnull @Nonnull
protected byte[] getMasterKey() { protected byte[] getKey() {
return Preconditions.checkNotNull( masterKey ); return Preconditions.checkNotNull( masterKey );
} }
public byte[] getKeyID() { 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, public abstract String encode(@Nonnull final String siteName, final MPSiteType siteType, int siteCounter,
@Nullable final String siteContext); final MPSiteVariant siteVariant, @Nullable final String siteContext);
public boolean isValid() { public boolean isValid() {
return masterKey != null; return masterKey != null;
@ -95,6 +95,10 @@ public abstract class MasterKey {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
masterKey = deriveKey( masterPassword ); masterKey = deriveKey( masterPassword );
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 ) ), logger.trc( "masterKey ID: %s (derived in %.2fs)", CodeUtils.encodeHex( idForBytes( masterKey ) ),
(System.currentTimeMillis() - start) / 1000D ); (System.currentTimeMillis() - start) / 1000D );

View File

@ -41,7 +41,7 @@ public class MasterKeyV0 extends MasterKey {
} }
@Override @Override
protected Version getAlgorithm() { public Version getAlgorithmVersion() {
return Version.V0; return Version.V0;
} }
@ -101,7 +101,7 @@ public class MasterKeyV0 extends MasterKey {
sitePasswordInfo = Bytes.concat( sitePasswordInfo, siteContextLengthBytes, siteContextBytes ); sitePasswordInfo = Bytes.concat( sitePasswordInfo, siteContextLengthBytes, siteContextBytes );
logger.trc( "sitePasswordInfo ID: %s", CodeUtils.encodeHex( idForBytes( sitePasswordInfo ) ) ); 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 ) ) ); logger.trc( "sitePasswordSeed ID: %s", CodeUtils.encodeHex( idForBytes( sitePasswordSeed ) ) );
Preconditions.checkState( sitePasswordSeed.length > 0 ); Preconditions.checkState( sitePasswordSeed.length > 0 );

View File

@ -1,15 +1,9 @@
package com.lyndir.masterpassword; package com.lyndir.masterpassword;
import com.google.common.base.Charsets;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.primitives.Bytes; import com.google.common.primitives.Bytes;
import com.lambdaworks.crypto.SCrypt;
import com.lyndir.lhunath.opal.system.*; import com.lyndir.lhunath.opal.system.*;
import com.lyndir.lhunath.opal.system.logging.Logger; 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; import javax.annotation.Nullable;
@ -30,7 +24,7 @@ public class MasterKeyV1 extends MasterKeyV0 {
} }
@Override @Override
protected Version getAlgorithm() { public Version getAlgorithmVersion() {
return Version.V1; return Version.V1;
} }
@ -64,7 +58,7 @@ public class MasterKeyV1 extends MasterKeyV0 {
sitePasswordInfo = Bytes.concat( sitePasswordInfo, siteContextLengthBytes, siteContextBytes ); sitePasswordInfo = Bytes.concat( sitePasswordInfo, siteContextLengthBytes, siteContextBytes );
logger.trc( "sitePasswordInfo ID: %s", CodeUtils.encodeHex( idForBytes( sitePasswordInfo ) ) ); 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 ) ) ); logger.trc( "sitePasswordSeed ID: %s", CodeUtils.encodeHex( idForBytes( sitePasswordSeed ) ) );
Preconditions.checkState( sitePasswordSeed.length > 0 ); Preconditions.checkState( sitePasswordSeed.length > 0 );

View File

@ -23,7 +23,7 @@ public class MasterKeyV2 extends MasterKeyV1 {
} }
@Override @Override
protected Version getAlgorithm() { public Version getAlgorithmVersion() {
return Version.V2; return Version.V2;
} }
@ -57,7 +57,7 @@ public class MasterKeyV2 extends MasterKeyV1 {
sitePasswordInfo = Bytes.concat( sitePasswordInfo, siteContextLengthBytes, siteContextBytes ); sitePasswordInfo = Bytes.concat( sitePasswordInfo, siteContextLengthBytes, siteContextBytes );
logger.trc( "sitePasswordInfo ID: %s", CodeUtils.encodeHex( idForBytes( sitePasswordInfo ) ) ); 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 ) ) ); logger.trc( "sitePasswordSeed ID: %s", CodeUtils.encodeHex( idForBytes( sitePasswordSeed ) ) );
Preconditions.checkState( sitePasswordSeed.length > 0 ); Preconditions.checkState( sitePasswordSeed.length > 0 );

View File

@ -26,7 +26,7 @@ public class MasterKeyV3 extends MasterKeyV2 {
} }
@Override @Override
protected Version getAlgorithm() { public Version getAlgorithmVersion() {
return Version.V3; return Version.V3;
} }

View File

@ -149,7 +149,7 @@ public class MPWTests {
} }
public char[] getMasterPassword() { public char[] getMasterPassword() {
return masterPassword.toCharArray(); return masterPassword == null? null: masterPassword.toCharArray();
} }
public String getKeyID() { public String getKeyID() {
@ -161,7 +161,7 @@ public class MPWTests {
} }
public int getSiteCounter() { public int getSiteCounter() {
return siteCounter; return ifNotNullElse( siteCounter, 1 );
} }
public MPSiteType getSiteType() { public MPSiteType getSiteType() {

View File

@ -13,13 +13,19 @@
<name>Master Password Android</name> <name>Master Password Android</name>
<description>An Android application to the Master Password algorithm</description> <description>An Android application to the Master Password algorithm</description>
<groupId>com.lyndir.masterpassword</groupId>
<artifactId>masterpassword-android</artifactId> <artifactId>masterpassword-android</artifactId>
<packaging>apk</packaging> <packaging>apk</packaging>
<!-- BUILD CONFIGURATION --> <!-- BUILD CONFIGURATION -->
<build> <build>
<plugins> <plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<configuration>
<timestampFormat>YYYYMMddHHmm</timestampFormat>
</configuration>
</plugin>
<plugin> <plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId> <groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId> <artifactId>android-maven-plugin</artifactId>
@ -30,9 +36,23 @@
<skip>false</skip> <skip>false</skip>
</zipalign> </zipalign>
<sdk> <sdk>
<platform>19</platform> <platform>21</platform>
</sdk> </sdk>
</configuration> </configuration>
<executions>
<execution>
<id>manifest-merger</id>
<phase>process-resources</phase>
<goals>
<goal>manifest-update</goal>
</goals>
<configuration>
<manifestVersionCode>${timestamp}</manifestVersionCode>
<manifestVersionName>${project.version}</manifestVersionName>
</configuration>
</execution>
</executions>
</plugin> </plugin>
</plugins> </plugins>
</build> </build>

View File

@ -1,15 +1,10 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@drawable/background">
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_gravity="center"
android:fillViewport="true"> android:fillViewport="true"
android:background="@drawable/background">
<LinearLayout <LinearLayout
android:orientation="horizontal" android:orientation="horizontal"
@ -33,4 +28,3 @@
android:layout_height="0dp" /> android:layout_height="0dp" />
</LinearLayout> </LinearLayout>
</HorizontalScrollView> </HorizontalScrollView>
</FrameLayout>

View File

@ -205,7 +205,7 @@ public class EmergencyActivity extends Activity {
final MasterKey.Version version = (MasterKey.Version) siteVersionField.getSelectedItem(); final MasterKey.Version version = (MasterKey.Version) siteVersionField.getSelectedItem();
try { try {
if (fullName.hashCode() == hc_userName && Arrays.hashCode( masterPassword ) == hc_masterPassword && if (fullName.hashCode() == hc_userName && Arrays.hashCode( masterPassword ) == hc_masterPassword &&
masterKeyFuture != null && masterKeyFuture.get().getAlgorithm() == version) masterKeyFuture != null && masterKeyFuture.get().getAlgorithmVersion() == version)
return; return;
} }
catch (InterruptedException | ExecutionException e) { catch (InterruptedException | ExecutionException e) {

View File

@ -1,7 +1,6 @@
package com.lyndir.masterpassword; package com.lyndir.masterpassword;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.Paint;
import android.graphics.Typeface; import android.graphics.Typeface;

View File

@ -2,16 +2,14 @@ package com.lyndir.masterpassword.model;
import static com.lyndir.lhunath.opal.system.util.StringUtils.strf; import static com.lyndir.lhunath.opal.system.util.StringUtils.strf;
import java.util.Objects;
/** /**
* @author lhunath, 2014-08-20 * @author lhunath, 2014-08-20
*/ */
public class User { public class User {
private String name; private final String name;
private Avatar avatar; private final Avatar avatar;
public User(final String name, final Avatar avatar) { public User(final String name, final Avatar avatar) {
this.name = name; this.name = name;

View File

@ -13,7 +13,6 @@
<name>Master Password CLI</name> <name>Master Password CLI</name>
<description>A CLI interface to the Master Password algorithm</description> <description>A CLI interface to the Master Password algorithm</description>
<groupId>com.lyndir.masterpassword</groupId>
<artifactId>masterpassword-cli</artifactId> <artifactId>masterpassword-cli</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>

View File

@ -45,7 +45,7 @@ public class CLI {
throws IOException { throws IOException {
// Read information from the environment. // Read information from the environment.
char[] masterPassword = null; char[] masterPassword;
String siteName = null, context = null; String siteName = null, context = null;
String userName = System.getenv( ENV_USERNAME ); String userName = System.getenv( ENV_USERNAME );
String siteTypeName = ifNotNullElse( System.getenv( ENV_SITETYPE ), "" ); String siteTypeName = ifNotNullElse( System.getenv( ENV_SITETYPE ), "" );

View File

@ -13,7 +13,6 @@
<name>Master Password GUI</name> <name>Master Password GUI</name>
<description>A GUI interface to the Master Password algorithm</description> <description>A GUI interface to the Master Password algorithm</description>
<groupId>com.lyndir.masterpassword</groupId>
<artifactId>masterpassword-gui</artifactId> <artifactId>masterpassword-gui</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>

View File

@ -21,8 +21,6 @@ import com.google.common.base.Charsets;
import com.google.common.io.*; import com.google.common.io.*;
import com.lyndir.lhunath.opal.system.logging.Logger; import com.lyndir.lhunath.opal.system.logging.Logger;
import com.lyndir.lhunath.opal.system.util.TypeUtils; import com.lyndir.lhunath.opal.system.util.TypeUtils;
import com.lyndir.masterpassword.MasterKey;
import com.lyndir.masterpassword.model.IncorrectMasterPasswordException;
import java.io.*; import java.io.*;
import java.net.URI; import java.net.URI;
import java.net.URL; import java.net.URL;
@ -41,7 +39,7 @@ public class GUI implements UnlockFrame.SignInCallback {
@SuppressWarnings("UnusedDeclaration") @SuppressWarnings("UnusedDeclaration")
private static final Logger logger = Logger.get( GUI.class ); 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; private PasswordFrame passwordFrame;
public static void main(final String[] args) public static void main(final String[] args)

View File

@ -1,6 +1,7 @@
package com.lyndir.masterpassword.gui; package com.lyndir.masterpassword.gui;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Preconditions;
import com.google.common.collect.*; import com.google.common.collect.*;
import com.lyndir.lhunath.opal.system.logging.Logger; import com.lyndir.lhunath.opal.system.logging.Logger;
import com.lyndir.masterpassword.model.MPUser; 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<MPUser, ModelUser>() { return FluentIterable.from( MPUserFileManager.get().getUsers() ).transform( new Function<MPUser, ModelUser>() {
@Nullable @Nullable
@Override @Override
public ModelUser apply(final MPUser model) { public ModelUser apply(@Nullable final MPUser model) {
return new ModelUser( model ); return new ModelUser( Preconditions.checkNotNull( model ) );
} }
} ).toArray( ModelUser.class ); } ).toArray( ModelUser.class );
} }

View File

@ -48,7 +48,7 @@ public class ModelUser extends User {
public void authenticate(final char[] masterPassword) public void authenticate(final char[] masterPassword)
throws IncorrectMasterPasswordException { throws IncorrectMasterPasswordException {
model.authenticate( masterPassword ); putKey( model.authenticate( masterPassword ) );
this.masterPassword = masterPassword; this.masterPassword = masterPassword;
} }
@ -81,6 +81,7 @@ public class ModelUser extends User {
} }
public boolean keySaved() { public boolean keySaved() {
// TODO
return false; return false;
} }
} }

View File

@ -1,7 +1,6 @@
package com.lyndir.masterpassword.gui; 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.google.common.collect.Maps;
import com.lyndir.masterpassword.MasterKey; import com.lyndir.masterpassword.MasterKey;
import com.lyndir.masterpassword.model.IncorrectMasterPasswordException; import com.lyndir.masterpassword.model.IncorrectMasterPasswordException;
@ -17,7 +16,7 @@ import javax.annotation.Nullable;
public abstract class User { public abstract class User {
@Nonnull @Nonnull
private static final EnumMap<MasterKey.Version, MasterKey> keyByVersion = Maps.newEnumMap( MasterKey.Version.class ); private final EnumMap<MasterKey.Version, MasterKey> keyByVersion = Maps.newEnumMap( MasterKey.Version.class );
public abstract String getFullName(); public abstract String getFullName();
@ -37,17 +36,23 @@ public abstract class User {
@Nonnull @Nonnull
public MasterKey getKey(MasterKey.Version algorithmVersion) { public MasterKey getKey(MasterKey.Version algorithmVersion) {
char[] masterPassword = getMasterPassword(); char[] masterPassword = Preconditions.checkNotNull( getMasterPassword(), "User is not authenticated: " + getFullName() );
MasterKey key = keyByVersion.get( algorithmVersion ); MasterKey key = keyByVersion.get( algorithmVersion );
if (key == null) if (key == null)
keyByVersion.put( algorithmVersion, key = MasterKey.create( algorithmVersion, getFullName(), masterPassword ) ); putKey( key = MasterKey.create( algorithmVersion, getFullName(), masterPassword ) );
if (!key.isValid()) if (!key.isValid())
key.revalidate( masterPassword ); key.revalidate( masterPassword );
return key; return key;
} }
protected void putKey(MasterKey masterKey) {
MasterKey oldKey = keyByVersion.put( masterKey.getAlgorithmVersion(), masterKey );
if (oldKey != null)
oldKey.invalidate();
}
public void reset() { public void reset() {
for (MasterKey key : keyByVersion.values()) for (MasterKey key : keyByVersion.values())
key.invalidate(); key.invalidate();

View File

@ -13,7 +13,6 @@
<name>Master Password Site Model</name> <name>Master Password Site Model</name>
<description>A persistence model for Master Password sites.</description> <description>A persistence model for Master Password sites.</description>
<groupId>com.lyndir.masterpassword</groupId>
<artifactId>masterpassword-model</artifactId> <artifactId>masterpassword-model</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>

View File

@ -1,6 +1,5 @@
package com.lyndir.masterpassword.model; 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 static com.lyndir.lhunath.opal.system.util.StringUtils.strf;
import com.lyndir.masterpassword.*; import com.lyndir.masterpassword.*;
@ -56,7 +55,7 @@ public class MPSite {
return resultFor( masterKey, MPSiteVariant.Password, null ); 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 ); return masterKey.encode( siteName, siteType, siteCounter, variant, context );
} }

View File

@ -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 static com.lyndir.lhunath.opal.system.util.StringUtils.strf;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.lyndir.lhunath.opal.system.CodeUtils;
import com.lyndir.masterpassword.MasterKey; import com.lyndir.masterpassword.MasterKey;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -51,11 +50,12 @@ public class MPSiteMarshaller {
} }
private String marshallHeader(final ContentMode contentMode, final MPUser user, @Nullable final MasterKey masterKey) { private String marshallHeader(final ContentMode contentMode, final MPUser user, @Nullable final MasterKey masterKey) {
this.contentMode = contentMode;
this.masterKey = masterKey; this.masterKey = masterKey;
StringBuilder header = new StringBuilder(); StringBuilder header = new StringBuilder();
header.append( "# Master Password site export\n" ); 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( "##\n" ); header.append( "##\n" );
header.append( "# Format: 1\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( "# Version: " ).append( MasterKey.Version.CURRENT.toBundleVersion() ).append( '\n' );
header.append( "# Algorithm: " ).append( MasterKey.Version.CURRENT.toInt() ).append( '\n' ); header.append( "# Algorithm: " ).append( MasterKey.Version.CURRENT.toInt() ).append( '\n' );
header.append( "# Default Type: " ).append( user.getDefaultType().getType() ).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( "#\n" ); header.append( "#\n" );
header.append( "# Last Times Password Login\t Site\tSite\n" ); header.append( "# Last Times Password Login\t Site\tSite\n" );

View File

@ -23,7 +23,7 @@ public class MPUser implements Comparable<MPUser> {
@Nullable @Nullable
private byte[] keyID; private byte[] keyID;
private MasterKey.Version algorithmVersion; private final MasterKey.Version algorithmVersion;
private int avatar; private int avatar;
private MPSiteType defaultType; private MPSiteType defaultType;
private ReadableInstant lastUsed; private ReadableInstant lastUsed;

View File

@ -58,9 +58,9 @@ public class MPUserFileManager extends MPUserManager {
} ) ) ).transform( new Function<File, MPUser>() { } ) ) ).transform( new Function<File, MPUser>() {
@Nullable @Nullable
@Override @Override
public MPUser apply(final File file) { public MPUser apply(@Nullable final File file) {
try { try {
return MPSiteUnmarshaller.unmarshall( file ).getUser(); return MPSiteUnmarshaller.unmarshall( Preconditions.checkNotNull( file ) ).getUser();
} }
catch (IOException e) { catch (IOException e) {
logger.err( e, "Couldn't read user from: %s", file ); logger.err( e, "Couldn't read user from: %s", file );

View File

@ -16,7 +16,7 @@ public abstract class MPUserManager {
return instance; return instance;
} }
public MPUserManager(final Iterable<MPUser> users) { protected MPUserManager(final Iterable<MPUser> users) {
for (MPUser user : users) for (MPUser user : users)
addUser( user ); addUser( user );
} }