mirror of
https://github.com/moparisthebest/open-keychain
synced 2025-02-23 06:12:20 -05:00
minor changes, add convertFingerprintToKeyId method
This commit is contained in:
parent
2b5023a75d
commit
ea7068acdf
@ -163,7 +163,7 @@ public class CertifyOperationTest {
|
|||||||
|
|
||||||
CertifyActionsParcel actions = new CertifyActionsParcel(mStaticRing1.getMasterKeyId());
|
CertifyActionsParcel actions = new CertifyActionsParcel(mStaticRing1.getMasterKeyId());
|
||||||
actions.add(new CertifyAction(mStaticRing2.getMasterKeyId(),
|
actions.add(new CertifyAction(mStaticRing2.getMasterKeyId(),
|
||||||
mStaticRing2.getPublicKey().getUnorderedUserIds()));
|
mStaticRing2.getPublicKey().getUnorderedUserIds(), null));
|
||||||
CertifyResult result = op.certify(actions, null);
|
CertifyResult result = op.certify(actions, null);
|
||||||
|
|
||||||
Assert.assertTrue("certification must succeed", result.success());
|
Assert.assertTrue("certification must succeed", result.success());
|
||||||
@ -213,7 +213,7 @@ public class CertifyOperationTest {
|
|||||||
|
|
||||||
CertifyActionsParcel actions = new CertifyActionsParcel(mStaticRing1.getMasterKeyId());
|
CertifyActionsParcel actions = new CertifyActionsParcel(mStaticRing1.getMasterKeyId());
|
||||||
actions.add(new CertifyAction(mStaticRing1.getMasterKeyId(),
|
actions.add(new CertifyAction(mStaticRing1.getMasterKeyId(),
|
||||||
mStaticRing2.getPublicKey().getUnorderedUserIds()));
|
mStaticRing2.getPublicKey().getUnorderedUserIds(), null));
|
||||||
|
|
||||||
CertifyResult result = op.certify(actions, null);
|
CertifyResult result = op.certify(actions, null);
|
||||||
|
|
||||||
@ -231,7 +231,7 @@ public class CertifyOperationTest {
|
|||||||
CertifyActionsParcel actions = new CertifyActionsParcel(mStaticRing1.getMasterKeyId());
|
CertifyActionsParcel actions = new CertifyActionsParcel(mStaticRing1.getMasterKeyId());
|
||||||
ArrayList<String> uids = new ArrayList<String>();
|
ArrayList<String> uids = new ArrayList<String>();
|
||||||
uids.add("nonexistent");
|
uids.add("nonexistent");
|
||||||
actions.add(new CertifyAction(1234L, uids));
|
actions.add(new CertifyAction(1234L, uids, null));
|
||||||
|
|
||||||
CertifyResult result = op.certify(actions, null);
|
CertifyResult result = op.certify(actions, null);
|
||||||
|
|
||||||
@ -243,7 +243,7 @@ public class CertifyOperationTest {
|
|||||||
{
|
{
|
||||||
CertifyActionsParcel actions = new CertifyActionsParcel(1234L);
|
CertifyActionsParcel actions = new CertifyActionsParcel(1234L);
|
||||||
actions.add(new CertifyAction(mStaticRing1.getMasterKeyId(),
|
actions.add(new CertifyAction(mStaticRing1.getMasterKeyId(),
|
||||||
mStaticRing2.getPublicKey().getUnorderedUserIds()));
|
mStaticRing2.getPublicKey().getUnorderedUserIds(), null));
|
||||||
|
|
||||||
CertifyResult result = op.certify(actions, null);
|
CertifyResult result = op.certify(actions, null);
|
||||||
|
|
||||||
|
@ -0,0 +1,44 @@
|
|||||||
|
package org.sufficientlysecure.keychain.util;
|
||||||
|
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.robolectric.RobolectricTestRunner;
|
||||||
|
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||||
|
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
@org.robolectric.annotation.Config(emulateSdk = 18) // Robolectric doesn't yet support 19
|
||||||
|
public class KeyFormattingUtilsTest {
|
||||||
|
|
||||||
|
static final byte[] fp = new byte[] {
|
||||||
|
(byte) 0xD4, (byte) 0xAB, (byte) 0x19, (byte) 0x29, (byte) 0x64,
|
||||||
|
(byte) 0xF7, (byte) 0x6A, (byte) 0x7F, (byte) 0x8F, (byte) 0x8A,
|
||||||
|
(byte) 0x9B, (byte) 0x35, (byte) 0x7B, (byte) 0xD1, (byte) 0x83,
|
||||||
|
(byte) 0x20, (byte) 0xDE, (byte) 0xAD, (byte) 0xFA, (byte) 0x11
|
||||||
|
};
|
||||||
|
static final long keyId = 0x7bd18320deadfa11L;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStuff() {
|
||||||
|
Assert.assertEquals(KeyFormattingUtils.convertFingerprintToKeyId(fp), keyId);
|
||||||
|
|
||||||
|
Assert.assertEquals(
|
||||||
|
"d4ab192964f76a7f8f8a9b357bd18320deadfa11",
|
||||||
|
KeyFormattingUtils.convertFingerprintToHex(fp)
|
||||||
|
);
|
||||||
|
|
||||||
|
Assert.assertEquals(
|
||||||
|
"0x7bd18320deadfa11",
|
||||||
|
KeyFormattingUtils.convertKeyIdToHex(keyId)
|
||||||
|
);
|
||||||
|
|
||||||
|
Assert.assertEquals(
|
||||||
|
"0xdeadfa11",
|
||||||
|
KeyFormattingUtils.convertKeyIdToHexShort(keyId)
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -2,9 +2,6 @@ package org.sufficientlysecure.keychain.util;
|
|||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by valodim on 9/15/14.
|
|
||||||
*/
|
|
||||||
public class TestingUtils {
|
public class TestingUtils {
|
||||||
public static String genPassphrase() {
|
public static String genPassphrase() {
|
||||||
return genPassphrase(false);
|
return genPassphrase(false);
|
||||||
|
@ -23,6 +23,7 @@ import android.os.Parcelable;
|
|||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.pgp.WrappedUserAttribute;
|
import org.sufficientlysecure.keychain.pgp.WrappedUserAttribute;
|
||||||
|
|
||||||
@ -81,17 +82,11 @@ public class CertifyActionsParcel implements Parcelable {
|
|||||||
final public ArrayList<String> mUserIds;
|
final public ArrayList<String> mUserIds;
|
||||||
final public ArrayList<WrappedUserAttribute> mUserAttributes;
|
final public ArrayList<WrappedUserAttribute> mUserAttributes;
|
||||||
|
|
||||||
public CertifyAction(long masterKeyId, ArrayList<String> userIds) {
|
public CertifyAction(long masterKeyId, List<String> userIds,
|
||||||
|
List<WrappedUserAttribute> attributes) {
|
||||||
mMasterKeyId = masterKeyId;
|
mMasterKeyId = masterKeyId;
|
||||||
mUserIds = userIds;
|
mUserIds = new ArrayList<>(userIds);
|
||||||
mUserAttributes = null;
|
mUserAttributes = new ArrayList<>(attributes);
|
||||||
}
|
|
||||||
|
|
||||||
public CertifyAction(long masterKeyId, ArrayList<String> userIds,
|
|
||||||
ArrayList<WrappedUserAttribute> attributes) {
|
|
||||||
mMasterKeyId = masterKeyId;
|
|
||||||
mUserIds = userIds;
|
|
||||||
mUserAttributes = attributes;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,7 +164,7 @@ public class MultiUserIdsAdapter extends CursorAdapter {
|
|||||||
|
|
||||||
CertifyAction action = actions.get(keyId);
|
CertifyAction action = actions.get(keyId);
|
||||||
if (actions.get(keyId) == null) {
|
if (actions.get(keyId) == null) {
|
||||||
actions.put(keyId, new CertifyAction(keyId, uids));
|
actions.put(keyId, new CertifyAction(keyId, uids, null));
|
||||||
} else {
|
} else {
|
||||||
action.mUserIds.addAll(uids);
|
action.mUserIds.addAll(uids);
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,7 @@ import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Algorithm;
|
|||||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Curve;
|
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Curve;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
import java.security.DigestException;
|
import java.security.DigestException;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
@ -249,6 +250,10 @@ public class KeyFormattingUtils {
|
|||||||
return hexString;
|
return hexString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static long convertFingerprintToKeyId(byte[] fingerprint) {
|
||||||
|
return ByteBuffer.wrap(fingerprint, 12, 8).getLong();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Makes a human-readable version of a key ID, which is usually 64 bits: lower-case, no
|
* Makes a human-readable version of a key ID, which is usually 64 bits: lower-case, no
|
||||||
* leading 0x, space-separated quartets (for keys whose length in hex is divisible by 4)
|
* leading 0x, space-separated quartets (for keys whose length in hex is divisible by 4)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user