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