mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-11 03:25:05 -05:00
wrapped-key-ring: encapsulate key flags
This commit is contained in:
parent
952bb99a24
commit
cd0aba9d43
@ -1,5 +1,6 @@
|
||||
package org.sufficientlysecure.keychain.pgp;
|
||||
|
||||
import org.spongycastle.bcpg.sig.KeyFlags;
|
||||
import org.spongycastle.openpgp.PGPSecretKey;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -7,6 +8,12 @@ import java.io.OutputStream;
|
||||
|
||||
public class UncachedSecretKey extends UncachedPublicKey {
|
||||
|
||||
public static final int CERTIFY_OTHER = KeyFlags.CERTIFY_OTHER;
|
||||
public static final int SIGN_DATA = KeyFlags.SIGN_DATA;
|
||||
public static final int ENCRYPT_COMMS = KeyFlags.ENCRYPT_COMMS;
|
||||
public static final int ENCRYPT_STORAGE = KeyFlags.ENCRYPT_STORAGE;
|
||||
public static final int AUTHENTICATION = KeyFlags.AUTHENTICATION;
|
||||
|
||||
final PGPSecretKey mSecretKey;
|
||||
|
||||
public UncachedSecretKey(PGPSecretKey secretKey) {
|
||||
|
@ -38,7 +38,6 @@ import android.widget.TextView;
|
||||
|
||||
import com.beardedhen.androidbootstrap.BootstrapButton;
|
||||
|
||||
import org.spongycastle.bcpg.sig.KeyFlags;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
|
||||
import org.sufficientlysecure.keychain.pgp.UncachedSecretKey;
|
||||
@ -244,11 +243,15 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
|
||||
mIsNewKey = isNewKey;
|
||||
if (isNewKey) {
|
||||
mUsage = usage;
|
||||
mChkCertify.setChecked((usage & KeyFlags.CERTIFY_OTHER) == KeyFlags.CERTIFY_OTHER);
|
||||
mChkSign.setChecked((usage & KeyFlags.SIGN_DATA) == KeyFlags.SIGN_DATA);
|
||||
mChkEncrypt.setChecked(((usage & KeyFlags.ENCRYPT_COMMS) == KeyFlags.ENCRYPT_COMMS) ||
|
||||
((usage & KeyFlags.ENCRYPT_STORAGE) == KeyFlags.ENCRYPT_STORAGE));
|
||||
mChkAuthenticate.setChecked((usage & KeyFlags.AUTHENTICATION) == KeyFlags.AUTHENTICATION);
|
||||
mChkCertify.setChecked(
|
||||
(usage & UncachedSecretKey.CERTIFY_OTHER) == UncachedSecretKey.CERTIFY_OTHER);
|
||||
mChkSign.setChecked(
|
||||
(usage & UncachedSecretKey.SIGN_DATA) == UncachedSecretKey.SIGN_DATA);
|
||||
mChkEncrypt.setChecked(
|
||||
((usage & UncachedSecretKey.ENCRYPT_COMMS) == UncachedSecretKey.ENCRYPT_COMMS) ||
|
||||
((usage & UncachedSecretKey.ENCRYPT_STORAGE) == UncachedSecretKey.ENCRYPT_STORAGE));
|
||||
mChkAuthenticate.setChecked(
|
||||
(usage & UncachedSecretKey.AUTHENTICATION) == UncachedSecretKey.AUTHENTICATION);
|
||||
} else {
|
||||
mUsage = key.getKeyUsage();
|
||||
mOriginalUsage = mUsage;
|
||||
@ -319,16 +322,16 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
|
||||
}
|
||||
|
||||
public int getUsage() {
|
||||
mUsage = (mUsage & ~KeyFlags.CERTIFY_OTHER) |
|
||||
(mChkCertify.isChecked() ? KeyFlags.CERTIFY_OTHER : 0);
|
||||
mUsage = (mUsage & ~KeyFlags.SIGN_DATA) |
|
||||
(mChkSign.isChecked() ? KeyFlags.SIGN_DATA : 0);
|
||||
mUsage = (mUsage & ~KeyFlags.ENCRYPT_COMMS) |
|
||||
(mChkEncrypt.isChecked() ? KeyFlags.ENCRYPT_COMMS : 0);
|
||||
mUsage = (mUsage & ~KeyFlags.ENCRYPT_STORAGE) |
|
||||
(mChkEncrypt.isChecked() ? KeyFlags.ENCRYPT_STORAGE : 0);
|
||||
mUsage = (mUsage & ~KeyFlags.AUTHENTICATION) |
|
||||
(mChkAuthenticate.isChecked() ? KeyFlags.AUTHENTICATION : 0);
|
||||
mUsage = (mUsage & ~UncachedSecretKey.CERTIFY_OTHER) |
|
||||
(mChkCertify.isChecked() ? UncachedSecretKey.CERTIFY_OTHER : 0);
|
||||
mUsage = (mUsage & ~UncachedSecretKey.SIGN_DATA) |
|
||||
(mChkSign.isChecked() ? UncachedSecretKey.SIGN_DATA : 0);
|
||||
mUsage = (mUsage & ~UncachedSecretKey.ENCRYPT_COMMS) |
|
||||
(mChkEncrypt.isChecked() ? UncachedSecretKey.ENCRYPT_COMMS : 0);
|
||||
mUsage = (mUsage & ~UncachedSecretKey.ENCRYPT_STORAGE) |
|
||||
(mChkEncrypt.isChecked() ? UncachedSecretKey.ENCRYPT_STORAGE : 0);
|
||||
mUsage = (mUsage & ~UncachedSecretKey.AUTHENTICATION) |
|
||||
(mChkAuthenticate.isChecked() ? UncachedSecretKey.AUTHENTICATION : 0);
|
||||
|
||||
return mUsage;
|
||||
}
|
||||
|
@ -35,7 +35,6 @@ import android.widget.TextView;
|
||||
|
||||
import com.beardedhen.androidbootstrap.BootstrapButton;
|
||||
|
||||
import org.spongycastle.openpgp.PGPKeyFlags;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.pgp.PgpConversionHelper;
|
||||
import org.sufficientlysecure.keychain.pgp.UncachedSecretKey;
|
||||
@ -420,7 +419,7 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
|
||||
view.setEditorListener(SectionView.this);
|
||||
int usage = 0;
|
||||
if (mEditors.getChildCount() == 0) {
|
||||
usage = PGPKeyFlags.CAN_CERTIFY;
|
||||
usage = UncachedSecretKey.CERTIFY_OTHER;
|
||||
}
|
||||
view.setValue(newKey, newKey.isMasterKey(), usage, true);
|
||||
mEditors.addView(view);
|
||||
|
Loading…
Reference in New Issue
Block a user