2
0

Format-specific marshalling.

This commit is contained in:
Maarten Billemont 2018-04-26 12:46:56 -04:00
parent 11185725d1
commit 10698284d2
4 changed files with 7 additions and 6 deletions

View File

@ -126,7 +126,7 @@ public class MPFileUserManager extends MPUserManager {
throws IOException { throws IOException {
return new OutputStreamWriter( new FileOutputStream( getUserFile( user ) ), Charsets.UTF_8 ); return new OutputStreamWriter( new FileOutputStream( getUserFile( user ) ), Charsets.UTF_8 );
} }
}.write( new MPFlatMarshaller().marshall( user, masterKey, MPMarshaller.ContentMode.PROTECTED ) ); }.write( user.getFormat().marshaller().marshall( user, masterKey, MPMarshaller.ContentMode.PROTECTED ) );
} }
catch (final IOException e) { catch (final IOException e) {
logger.err( e, "Unable to save sites for user: %s", user ); logger.err( e, "Unable to save sites for user: %s", user );

View File

@ -36,7 +36,7 @@ public class MPFlatMarshaller implements MPMarshaller {
@Nonnull @Nonnull
@Override @Override
public String marshall(final MPFileUser user, final MPMasterKey masterKey, final ContentMode contentMode) public String marshall(final MPFileUser user, final MPMasterKey masterKey, final ContentMode contentMode)
throws MPInvalidatedException { throws MPInvalidatedException, MPMarshalException {
StringBuilder content = new StringBuilder(); StringBuilder content = new StringBuilder();
content.append( "# Master Password site export\n" ); content.append( "# Master Password site export\n" );
content.append( "# " ).append( contentMode.description() ).append( '\n' ); content.append( "# " ).append( contentMode.description() ).append( '\n' );

View File

@ -18,6 +18,7 @@
package com.lyndir.masterpassword.model; package com.lyndir.masterpassword.model;
import com.lyndir.masterpassword.MPInvalidatedException;
import com.lyndir.masterpassword.MPMasterKey; import com.lyndir.masterpassword.MPMasterKey;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -29,8 +30,8 @@ public class MPJSONMarshaller implements MPMarshaller {
@Nonnull @Nonnull
@Override @Override
public String marshall(final MPFileUser user, final MPMasterKey masterKey, final ContentMode contentMode) { public String marshall(final MPFileUser user, final MPMasterKey masterKey, final ContentMode contentMode)
// TODO throws MPInvalidatedException, MPMarshalException {
return null; throw new MPMarshalException( "Not yet implemented" );
} }
} }

View File

@ -30,7 +30,7 @@ public interface MPMarshaller {
@Nonnull @Nonnull
String marshall(MPFileUser user, MPMasterKey masterKey, ContentMode contentMode) String marshall(MPFileUser user, MPMasterKey masterKey, ContentMode contentMode)
throws MPInvalidatedException; throws MPInvalidatedException, MPMarshalException;
enum ContentMode { enum ContentMode {
PROTECTED( "Export of site names and stored passwords (unless device-private) encrypted with the master key." ), PROTECTED( "Export of site names and stored passwords (unless device-private) encrypted with the master key." ),