Standardize on a naming scheme: cipher -> template, userName -> fullName, element -> site.
This commit is contained in:
@@ -1,27 +0,0 @@
|
||||
package com.lyndir.masterpassword;
|
||||
|
||||
import com.lyndir.masterpassword.entity.*;
|
||||
|
||||
|
||||
/**
|
||||
* <i>07 04, 2012</i>
|
||||
*
|
||||
* @author lhunath
|
||||
*/
|
||||
public enum MPElementTypeClass {
|
||||
|
||||
Generated(MPElementGeneratedEntity.class),
|
||||
Stored(MPElementStoredEntity.class);
|
||||
|
||||
private final Class<? extends MPElementEntity> entityClass;
|
||||
|
||||
MPElementTypeClass(final Class<? extends MPElementEntity> entityClass) {
|
||||
|
||||
this.entityClass = entityClass;
|
||||
}
|
||||
|
||||
public Class<? extends MPElementEntity> getEntityClass() {
|
||||
|
||||
return entityClass;
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ package com.lyndir.masterpassword;
|
||||
*
|
||||
* @author lhunath
|
||||
*/
|
||||
public enum MPElementFeature {
|
||||
public enum MPSiteFeature {
|
||||
|
||||
/** Export the key-protected content data. */
|
||||
ExportContent,
|
||||
@@ -5,7 +5,6 @@ import com.google.common.collect.ImmutableSet;
|
||||
import com.lyndir.lhunath.opal.system.logging.Logger;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import javax.annotation.Generated;
|
||||
|
||||
|
||||
/**
|
||||
@@ -13,14 +12,14 @@ import javax.annotation.Generated;
|
||||
*
|
||||
* @author lhunath
|
||||
*/
|
||||
public enum MPElementType {
|
||||
public enum MPSiteType {
|
||||
|
||||
GeneratedMaximum( "20 characters, contains symbols.", //
|
||||
ImmutableList.of( "x", "max", "maximum" ), MPElementTypeClass.Generated, //
|
||||
ImmutableList.of( "x", "max", "maximum" ), MPSiteTypeClass.Generated, //
|
||||
ImmutableList.of( new MPTemplate( "anoxxxxxxxxxxxxxxxxx" ), new MPTemplate( "axxxxxxxxxxxxxxxxxno" ) ) ),
|
||||
|
||||
GeneratedLong( "Copy-friendly, 14 characters, contains symbols.", //
|
||||
ImmutableList.of( "l", "long" ), MPElementTypeClass.Generated, //
|
||||
ImmutableList.of( "l", "long" ), MPSiteTypeClass.Generated, //
|
||||
ImmutableList.of( new MPTemplate( "CvcvnoCvcvCvcv" ), new MPTemplate( "CvcvCvcvnoCvcv" ),
|
||||
new MPTemplate( "CvcvCvcvCvcvno" ), new MPTemplate( "CvccnoCvcvCvcv" ),
|
||||
new MPTemplate( "CvccCvcvnoCvcv" ), new MPTemplate( "CvccCvcvCvcvno" ),
|
||||
@@ -34,56 +33,56 @@ public enum MPElementType {
|
||||
new MPTemplate( "CvccCvcvCvccno" ) ) ),
|
||||
|
||||
GeneratedMedium( "Copy-friendly, 8 characters, contains symbols.", //
|
||||
ImmutableList.of( "m", "med", "medium" ), MPElementTypeClass.Generated, //
|
||||
ImmutableList.of( "m", "med", "medium" ), MPSiteTypeClass.Generated, //
|
||||
ImmutableList.of( new MPTemplate( "CvcnoCvc" ), new MPTemplate( "CvcCvcno" ) ) ),
|
||||
|
||||
GeneratedBasic( "8 characters, no symbols.", //
|
||||
ImmutableList.of( "b", "basic" ), MPElementTypeClass.Generated, //
|
||||
ImmutableList.of( "b", "basic" ), MPSiteTypeClass.Generated, //
|
||||
ImmutableList.of( new MPTemplate( "aaanaaan" ), new MPTemplate( "aannaaan" ), new MPTemplate( "aaannaaa" ) ) ),
|
||||
|
||||
GeneratedShort( "Copy-friendly, 4 characters, no symbols.", //
|
||||
ImmutableList.of( "s", "short" ), MPElementTypeClass.Generated, //
|
||||
ImmutableList.of( "s", "short" ), MPSiteTypeClass.Generated, //
|
||||
ImmutableList.of( new MPTemplate( "Cvcn" ) ) ),
|
||||
|
||||
GeneratedPIN( "4 numbers.", //
|
||||
ImmutableList.of( "i", "pin" ), MPElementTypeClass.Generated, //
|
||||
ImmutableList.of( "i", "pin" ), MPSiteTypeClass.Generated, //
|
||||
ImmutableList.of( new MPTemplate( "nnnn" ) ) ),
|
||||
|
||||
GeneratedName( "9 letter name.", //
|
||||
ImmutableList.of( "n", "name" ), MPElementTypeClass.Generated, //
|
||||
ImmutableList.of( "n", "name" ), MPSiteTypeClass.Generated, //
|
||||
ImmutableList.of( new MPTemplate( "cvccvcvcv" ) ) ),
|
||||
|
||||
GeneratedPhrase( "20 character sentence.", //
|
||||
ImmutableList.of( "p", "phrase" ), MPElementTypeClass.Generated, //
|
||||
ImmutableList.of( "p", "phrase" ), MPSiteTypeClass.Generated, //
|
||||
ImmutableList.of( new MPTemplate( "cvcc cvc cvccvcv cvc" ), new MPTemplate( "cvc cvccvcvcv cvcv" ),
|
||||
new MPTemplate( "cv cvccv cvc cvcvccv" ) ) ),
|
||||
|
||||
StoredPersonal( "AES-encrypted, exportable.", //
|
||||
ImmutableList.of( "personal" ), MPElementTypeClass.Stored, //
|
||||
ImmutableList.<MPTemplate>of(), MPElementFeature.ExportContent ),
|
||||
ImmutableList.of( "personal" ), MPSiteTypeClass.Stored, //
|
||||
ImmutableList.<MPTemplate>of(), MPSiteFeature.ExportContent ),
|
||||
|
||||
StoredDevicePrivate( "AES-encrypted, not exported.", //
|
||||
ImmutableList.of( "device" ), MPElementTypeClass.Stored, //
|
||||
ImmutableList.<MPTemplate>of(), MPElementFeature.DevicePrivate );
|
||||
ImmutableList.of( "device" ), MPSiteTypeClass.Stored, //
|
||||
ImmutableList.<MPTemplate>of(), MPSiteFeature.DevicePrivate );
|
||||
|
||||
static final Logger logger = Logger.get( MPElementType.class );
|
||||
static final Logger logger = Logger.get( MPSiteType.class );
|
||||
|
||||
private final String description;
|
||||
private final List<String> options;
|
||||
private final MPElementTypeClass typeClass;
|
||||
private final List<MPTemplate> templates;
|
||||
private final Set<MPElementFeature> typeFeatures;
|
||||
private final String description;
|
||||
private final List<String> options;
|
||||
private final MPSiteTypeClass typeClass;
|
||||
private final List<MPTemplate> templates;
|
||||
private final Set<MPSiteFeature> typeFeatures;
|
||||
|
||||
MPElementType(final String description, final List<String> options, final MPElementTypeClass typeClass,
|
||||
final List<MPTemplate> templates, final MPElementFeature... typeFeatures) {
|
||||
MPSiteType(final String description, final List<String> options, final MPSiteTypeClass typeClass, final List<MPTemplate> templates,
|
||||
final MPSiteFeature... typeFeatures) {
|
||||
|
||||
this.description = description;
|
||||
this.options = options;
|
||||
this.typeClass = typeClass;
|
||||
this.templates = templates;
|
||||
|
||||
ImmutableSet.Builder<MPElementFeature> typeFeaturesBuilder = ImmutableSet.builder();
|
||||
for (final MPElementFeature typeFeature : typeFeatures) {
|
||||
ImmutableSet.Builder<MPSiteFeature> typeFeaturesBuilder = ImmutableSet.builder();
|
||||
for (final MPSiteFeature typeFeature : typeFeatures) {
|
||||
typeFeaturesBuilder.add( typeFeature );
|
||||
}
|
||||
this.typeFeatures = typeFeaturesBuilder.build();
|
||||
@@ -98,12 +97,12 @@ public enum MPElementType {
|
||||
return options;
|
||||
}
|
||||
|
||||
public MPElementTypeClass getTypeClass() {
|
||||
public MPSiteTypeClass getTypeClass() {
|
||||
|
||||
return typeClass;
|
||||
}
|
||||
|
||||
public Set<MPElementFeature> getTypeFeatures() {
|
||||
public Set<MPSiteFeature> getTypeFeatures() {
|
||||
|
||||
return typeFeatures;
|
||||
}
|
||||
@@ -113,9 +112,9 @@ public enum MPElementType {
|
||||
*
|
||||
* @return The type registered for the given option.
|
||||
*/
|
||||
public static MPElementType forOption(final String option) {
|
||||
public static MPSiteType forOption(final String option) {
|
||||
|
||||
for (final MPElementType type : values())
|
||||
for (final MPSiteType type : values())
|
||||
if (type.getOptions().contains( option.toLowerCase() ))
|
||||
return type;
|
||||
|
||||
@@ -127,12 +126,12 @@ public enum MPElementType {
|
||||
*
|
||||
* @return The type registered with the given name.
|
||||
*/
|
||||
public static MPElementType forName(final String name) {
|
||||
public static MPSiteType forName(final String name) {
|
||||
|
||||
if (name == null)
|
||||
return null;
|
||||
|
||||
for (final MPElementType type : values())
|
||||
for (final MPSiteType type : values())
|
||||
if (type.name().equalsIgnoreCase( name ))
|
||||
return type;
|
||||
|
||||
@@ -144,10 +143,10 @@ public enum MPElementType {
|
||||
*
|
||||
* @return All types that support the given class.
|
||||
*/
|
||||
public static ImmutableList<MPElementType> forClass(final MPElementTypeClass typeClass) {
|
||||
public static ImmutableList<MPSiteType> forClass(final MPSiteTypeClass typeClass) {
|
||||
|
||||
ImmutableList.Builder<MPElementType> types = ImmutableList.builder();
|
||||
for (final MPElementType type : values())
|
||||
ImmutableList.Builder<MPSiteType> types = ImmutableList.builder();
|
||||
for (final MPSiteType type : values())
|
||||
if (type.getTypeClass() == typeClass)
|
||||
types.add( type );
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.lyndir.masterpassword;
|
||||
|
||||
/**
|
||||
* <i>07 04, 2012</i>
|
||||
*
|
||||
* @author lhunath
|
||||
*/
|
||||
public enum MPSiteTypeClass {
|
||||
Generated,
|
||||
Stored
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import java.util.List;
|
||||
/**
|
||||
* @author lhunath, 14-12-02
|
||||
*/
|
||||
public enum MPElementVariant {
|
||||
public enum MPSiteVariant {
|
||||
Password( "The password to log in with.", "Doesn't currently use a context.", //
|
||||
ImmutableList.of( "p", "password" ), "com.lyndir.masterpassword" ),
|
||||
Login( "The username to log in as.", "Doesn't currently use a context.", //
|
||||
@@ -16,14 +16,14 @@ public enum MPElementVariant {
|
||||
Answer( "The answer to a security question.", "Empty for a universal site answer or\nthe most significant word(s) of the question.", //
|
||||
ImmutableList.of( "a", "answer" ), "com.lyndir.masterpassword.answer" );
|
||||
|
||||
static final Logger logger = Logger.get( MPElementType.class );
|
||||
static final Logger logger = Logger.get( MPSiteType.class );
|
||||
|
||||
private final String description;
|
||||
private final String contextDescription;
|
||||
private final List<String> options;
|
||||
private final String scope;
|
||||
|
||||
MPElementVariant(final String description, final String contextDescription, final List<String> options, final String scope) {
|
||||
MPSiteVariant(final String description, final String contextDescription, final List<String> options, final String scope) {
|
||||
this.contextDescription = contextDescription;
|
||||
|
||||
this.options = options;
|
||||
@@ -52,9 +52,9 @@ public enum MPElementVariant {
|
||||
*
|
||||
* @return The variant registered for the given option.
|
||||
*/
|
||||
public static MPElementVariant forOption(final String option) {
|
||||
public static MPSiteVariant forOption(final String option) {
|
||||
|
||||
for (final MPElementVariant variant : values())
|
||||
for (final MPSiteVariant variant : values())
|
||||
if (variant.getOptions().contains( option.toLowerCase() ))
|
||||
return variant;
|
||||
|
||||
@@ -65,12 +65,12 @@ public enum MPElementVariant {
|
||||
*
|
||||
* @return The variant registered with the given name.
|
||||
*/
|
||||
public static MPElementVariant forName(final String name) {
|
||||
public static MPSiteVariant forName(final String name) {
|
||||
|
||||
if (name == null)
|
||||
return null;
|
||||
|
||||
for (final MPElementVariant type : values())
|
||||
for (final MPSiteVariant type : values())
|
||||
if (type.name().equalsIgnoreCase( name ))
|
||||
return type;
|
||||
|
||||
@@ -4,7 +4,6 @@ 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.crypto.CryptUtils;
|
||||
import com.lyndir.lhunath.opal.system.*;
|
||||
import com.lyndir.lhunath.opal.system.logging.Logger;
|
||||
import java.nio.ByteBuffer;
|
||||
@@ -32,22 +31,22 @@ public class MasterKey {
|
||||
private static final MessageDigests MP_hash = MessageDigests.SHA256;
|
||||
private static final MessageAuthenticationDigests MP_mac = MessageAuthenticationDigests.HmacSHA256;
|
||||
|
||||
private final String userName;
|
||||
private final String fullName;
|
||||
private final byte[] masterKey;
|
||||
|
||||
private boolean valid;
|
||||
|
||||
public MasterKey(final String userName, final String masterPassword) {
|
||||
public MasterKey(final String fullName, final String masterPassword) {
|
||||
|
||||
this.userName = userName;
|
||||
logger.trc( "userName: %s", userName );
|
||||
this.fullName = fullName;
|
||||
logger.trc( "fullName: %s", fullName );
|
||||
logger.trc( "masterPassword: %s", masterPassword );
|
||||
|
||||
long start = System.currentTimeMillis();
|
||||
byte[] userNameBytes = userName.getBytes( MP_charset );
|
||||
byte[] userNameBytes = fullName.getBytes( MP_charset );
|
||||
byte[] userNameLengthBytes = bytesForInt( userNameBytes.length );
|
||||
|
||||
String mpKeyScope = MPElementVariant.Password.getScope();
|
||||
String mpKeyScope = MPSiteVariant.Password.getScope();
|
||||
byte[] masterKeySalt = Bytes.concat( mpKeyScope.getBytes( MP_charset ), userNameLengthBytes, userNameBytes );
|
||||
logger.trc( "key scope: %s", mpKeyScope );
|
||||
logger.trc( "masterKeySalt ID: %s", idForBytes( masterKeySalt ) );
|
||||
@@ -63,9 +62,9 @@ public class MasterKey {
|
||||
}
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
public String getFullName() {
|
||||
|
||||
return userName;
|
||||
return fullName;
|
||||
}
|
||||
|
||||
public String getKeyID() {
|
||||
@@ -74,7 +73,7 @@ public class MasterKey {
|
||||
return idForBytes( masterKey );
|
||||
}
|
||||
|
||||
private byte[] getSubkey(final int subkeyLength) {
|
||||
private byte[] getSubKey(final int subkeyLength) {
|
||||
|
||||
Preconditions.checkState( valid );
|
||||
byte[] subkey = new byte[Math.min( subkeyLength, masterKey.length )];
|
||||
@@ -83,10 +82,10 @@ public class MasterKey {
|
||||
return subkey;
|
||||
}
|
||||
|
||||
public String encode(final String siteName, final MPElementType siteType, int siteCounter, final MPElementVariant siteVariant,
|
||||
public String encode(final String siteName, final MPSiteType siteType, int siteCounter, final MPSiteVariant siteVariant,
|
||||
@Nullable final String siteContext) {
|
||||
Preconditions.checkState( valid );
|
||||
Preconditions.checkArgument( siteType.getTypeClass() == MPElementTypeClass.Generated );
|
||||
Preconditions.checkArgument( siteType.getTypeClass() == MPSiteTypeClass.Generated );
|
||||
Preconditions.checkArgument( !siteName.isEmpty() );
|
||||
|
||||
logger.trc( "siteName: %s", siteName );
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
package com.lyndir.masterpassword.entity;
|
||||
|
||||
/**
|
||||
* <i>07 04, 2012</i>
|
||||
*
|
||||
* @author lhunath
|
||||
*/
|
||||
public class MPElementEntity {
|
||||
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package com.lyndir.masterpassword.entity;
|
||||
|
||||
/**
|
||||
* <i>07 04, 2012</i>
|
||||
*
|
||||
* @author lhunath
|
||||
*/
|
||||
public class MPElementGeneratedEntity extends MPElementEntity {
|
||||
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package com.lyndir.masterpassword.entity;
|
||||
|
||||
/**
|
||||
* <i>07 04, 2012</i>
|
||||
*
|
||||
* @author lhunath
|
||||
*/
|
||||
public class MPElementStoredEntity extends MPElementEntity {
|
||||
|
||||
}
|
||||
@@ -2,9 +2,7 @@ package com.lyndir.masterpassword;
|
||||
|
||||
import static com.lyndir.lhunath.opal.system.util.ObjectUtils.*;
|
||||
|
||||
import com.google.common.base.Verify;
|
||||
import com.lyndir.lhunath.opal.system.logging.Logger;
|
||||
import com.lyndir.lhunath.opal.system.util.NFunctionNN;
|
||||
import com.lyndir.lhunath.opal.system.util.NNSupplier;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -165,12 +163,12 @@ public class MPWTests {
|
||||
return siteCounter;
|
||||
}
|
||||
|
||||
public MPElementType getSiteType() {
|
||||
return MPElementType.forName( siteType );
|
||||
public MPSiteType getSiteType() {
|
||||
return MPSiteType.forName( siteType );
|
||||
}
|
||||
|
||||
public MPElementVariant getSiteVariant() {
|
||||
return MPElementVariant.forName( siteVariant );
|
||||
public MPSiteVariant getSiteVariant() {
|
||||
return MPSiteVariant.forName( siteVariant );
|
||||
}
|
||||
|
||||
public String getSiteContext() {
|
||||
|
||||
@@ -6,7 +6,6 @@ import com.google.common.io.Resources;
|
||||
import com.lyndir.lhunath.opal.system.logging.Logger;
|
||||
import java.net.URL;
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@@ -46,7 +45,7 @@ public class MasterKeyTest {
|
||||
public void testGetUserName()
|
||||
throws Exception {
|
||||
|
||||
assertEquals( new MasterKey( defaultCase.getFullName(), defaultCase.getMasterPassword() ).getUserName(),
|
||||
assertEquals( new MasterKey( defaultCase.getFullName(), defaultCase.getMasterPassword() ).getFullName(),
|
||||
defaultCase.getFullName() );
|
||||
}
|
||||
|
||||
|
||||
@@ -87,8 +87,8 @@ public class EmergencyActivity extends Activity {
|
||||
sitePasswordField.setPaintFlags( userNameField.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG );
|
||||
|
||||
typeField.setAdapter(
|
||||
new ArrayAdapter<MPElementType>( this, R.layout.type_item, MPElementType.forClass( MPElementTypeClass.Generated ) ) );
|
||||
typeField.setSelection( MPElementType.GeneratedLong.ordinal() );
|
||||
new ArrayAdapter<MPSiteType>( this, R.layout.type_item, MPSiteType.forClass( MPSiteTypeClass.Generated ) ) );
|
||||
typeField.setSelection( MPSiteType.GeneratedLong.ordinal() );
|
||||
|
||||
counterField.setMinValue( 1 );
|
||||
counterField.setMaxValue( Integer.MAX_VALUE );
|
||||
@@ -170,7 +170,7 @@ public class EmergencyActivity extends Activity {
|
||||
|
||||
private void updateSitePassword() {
|
||||
final String siteName = siteNameField.getText().toString();
|
||||
final MPElementType type = (MPElementType) typeField.getSelectedItem();
|
||||
final MPSiteType type = (MPSiteType) typeField.getSelectedItem();
|
||||
final int counter = counterField.getValue();
|
||||
|
||||
if (masterKeyFuture == null || siteName.isEmpty() || type == null) {
|
||||
|
||||
@@ -48,8 +48,8 @@ public class CLI {
|
||||
String siteName = null, masterPassword, context = null;
|
||||
String userName = System.getenv( ENV_USERNAME );
|
||||
String siteTypeName = ifNotNullElse( System.getenv( ENV_SITETYPE ), "" );
|
||||
MPElementType siteType = siteTypeName.isEmpty()? MPElementType.GeneratedLong: MPElementType.forOption( siteTypeName );
|
||||
MPElementVariant variant = MPElementVariant.Password;
|
||||
MPSiteType siteType = siteTypeName.isEmpty()? MPSiteType.GeneratedLong: MPSiteType.forOption( siteTypeName );
|
||||
MPSiteVariant variant = MPSiteVariant.Password;
|
||||
String siteCounterName = ifNotNullElse( System.getenv( ENV_SITECOUNTER ), "" );
|
||||
int siteCounter = siteCounterName.isEmpty()? 1: Integer.parseInt( siteCounterName );
|
||||
|
||||
@@ -68,7 +68,7 @@ public class CLI {
|
||||
else if ("-t".equals( arg ) || "--type".equals( arg ))
|
||||
typeArg = true;
|
||||
else if (typeArg) {
|
||||
siteType = MPElementType.forOption( arg );
|
||||
siteType = MPSiteType.forOption( arg );
|
||||
typeArg = false;
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ public class CLI {
|
||||
else if ("-v".equals( arg ) || "--variant".equals( arg ))
|
||||
variantArg = true;
|
||||
else if (variantArg) {
|
||||
variant = MPElementVariant.forOption( arg );
|
||||
variant = MPSiteVariant.forOption( arg );
|
||||
variantArg = false;
|
||||
}
|
||||
|
||||
@@ -106,13 +106,13 @@ public class CLI {
|
||||
System.out.format( " Defaults to %s in env or 'long' for password, 'name' for login.\n", ENV_SITETYPE );
|
||||
|
||||
int optionsLength = 0;
|
||||
Map<String, MPElementType> typeMap = Maps.newLinkedHashMap();
|
||||
for (MPElementType elementType : MPElementType.values()) {
|
||||
Map<String, MPSiteType> typeMap = Maps.newLinkedHashMap();
|
||||
for (MPSiteType elementType : MPSiteType.values()) {
|
||||
String options = Joiner.on( ", " ).join( elementType.getOptions() );
|
||||
typeMap.put( options, elementType );
|
||||
optionsLength = Math.max( optionsLength, options.length() );
|
||||
}
|
||||
for (Map.Entry<String, MPElementType> entry : typeMap.entrySet()) {
|
||||
for (Map.Entry<String, MPSiteType> entry : typeMap.entrySet()) {
|
||||
String infoString = strf( " -v %" + optionsLength + "s | ", entry.getKey() );
|
||||
String infoNewline = "\n" + StringUtils.repeat( " ", infoString.length() - 3 ) + " | ";
|
||||
infoString += entry.getValue().getDescription().replaceAll( "\n", infoNewline );
|
||||
@@ -126,13 +126,13 @@ public class CLI {
|
||||
System.out.format( " Defaults to 'password'.\n" );
|
||||
|
||||
optionsLength = 0;
|
||||
Map<String, MPElementVariant> variantMap = Maps.newLinkedHashMap();
|
||||
for (MPElementVariant elementVariant : MPElementVariant.values()) {
|
||||
Map<String, MPSiteVariant> variantMap = Maps.newLinkedHashMap();
|
||||
for (MPSiteVariant elementVariant : MPSiteVariant.values()) {
|
||||
String options = Joiner.on( ", " ).join( elementVariant.getOptions() );
|
||||
variantMap.put( options, elementVariant );
|
||||
optionsLength = Math.max( optionsLength, options.length() );
|
||||
}
|
||||
for (Map.Entry<String, MPElementVariant> entry : variantMap.entrySet()) {
|
||||
for (Map.Entry<String, MPSiteVariant> entry : variantMap.entrySet()) {
|
||||
String infoString = strf( " -v %" + optionsLength + "s | ", entry.getKey() );
|
||||
String infoNewline = "\n" + StringUtils.repeat( " ", infoString.length() - 3 ) + " | ";
|
||||
infoString += entry.getValue().getDescription().replaceAll( "\n", infoNewline );
|
||||
@@ -142,7 +142,7 @@ public class CLI {
|
||||
|
||||
System.out.format( " -C context A variant-specific context.\n" );
|
||||
System.out.format( " Defaults to empty.\n" );
|
||||
for (Map.Entry<String, MPElementVariant> entry : variantMap.entrySet()) {
|
||||
for (Map.Entry<String, MPSiteVariant> entry : variantMap.entrySet()) {
|
||||
String infoString = strf( " -v %" + optionsLength + "s | ", entry.getKey() );
|
||||
String infoNewline = "\n" + StringUtils.repeat( " ", infoString.length() - 3 ) + " | ";
|
||||
infoString += entry.getValue().getContextDescription().replaceAll( "\n", infoNewline );
|
||||
|
||||
@@ -17,12 +17,12 @@ import javax.swing.event.*;
|
||||
*/
|
||||
public class PasswordFrame extends JFrame implements DocumentListener {
|
||||
|
||||
private final User user;
|
||||
private final JTextField siteNameField;
|
||||
private final JComboBox<MPElementType> siteTypeField;
|
||||
private final JSpinner siteCounterField;
|
||||
private final JTextField passwordField;
|
||||
private final JLabel tipLabel;
|
||||
private final User user;
|
||||
private final JTextField siteNameField;
|
||||
private final JComboBox<MPSiteType> siteTypeField;
|
||||
private final JSpinner siteCounterField;
|
||||
private final JTextField passwordField;
|
||||
private final JLabel tipLabel;
|
||||
|
||||
public PasswordFrame(User user)
|
||||
throws HeadlessException {
|
||||
@@ -89,7 +89,7 @@ public class PasswordFrame extends JFrame implements DocumentListener {
|
||||
} );
|
||||
|
||||
// Site Type & Counter
|
||||
MPElementType[] types = Iterables.toArray( MPElementType.forClass( MPElementTypeClass.Generated ), MPElementType.class );
|
||||
MPSiteType[] types = Iterables.toArray( MPSiteType.forClass( MPSiteTypeClass.Generated ), MPSiteType.class );
|
||||
JComponent siteSettings = Components.boxLayout( BoxLayout.LINE_AXIS, //
|
||||
siteTypeField = new JComboBox<>( types ), //
|
||||
siteCounterField = new JSpinner(
|
||||
@@ -104,7 +104,7 @@ public class PasswordFrame extends JFrame implements DocumentListener {
|
||||
siteTypeField.setFont( Res.exoRegular().deriveFont( 12f ) );
|
||||
siteTypeField.setAlignmentX( LEFT_ALIGNMENT );
|
||||
siteTypeField.setAlignmentY( CENTER_ALIGNMENT );
|
||||
siteTypeField.setSelectedItem( MPElementType.GeneratedLong );
|
||||
siteTypeField.setSelectedItem( MPSiteType.GeneratedLong );
|
||||
siteTypeField.addItemListener( new ItemListener() {
|
||||
@Override
|
||||
public void itemStateChanged(final ItemEvent e) {
|
||||
@@ -146,11 +146,11 @@ public class PasswordFrame extends JFrame implements DocumentListener {
|
||||
}
|
||||
|
||||
private void updatePassword(final PasswordCallback callback) {
|
||||
final MPElementType siteType = (MPElementType) siteTypeField.getSelectedItem();
|
||||
final MPSiteType siteType = (MPSiteType) siteTypeField.getSelectedItem();
|
||||
final String siteName = siteNameField.getText();
|
||||
final int siteCounter = (Integer) siteCounterField.getValue();
|
||||
|
||||
if (siteType.getTypeClass() != MPElementTypeClass.Generated || siteName == null || siteName.isEmpty() || !user.hasKey()) {
|
||||
if (siteType.getTypeClass() != MPSiteTypeClass.Generated || siteName == null || siteName.isEmpty() || !user.hasKey()) {
|
||||
passwordField.setText( null );
|
||||
tipLabel.setText( null );
|
||||
return;
|
||||
@@ -159,7 +159,7 @@ public class PasswordFrame extends JFrame implements DocumentListener {
|
||||
Res.execute( new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final String sitePassword = user.getKey().encode( siteName, siteType, siteCounter, MPElementVariant.Password, null );
|
||||
final String sitePassword = user.getKey().encode( siteName, siteType, siteCounter, MPSiteVariant.Password, null );
|
||||
if (callback != null)
|
||||
callback.passwordGenerated( siteName, sitePassword );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user