Search in sources :

Example 1 with PrimitiveSet

use of com.google.crypto.tink.PrimitiveSet in project tink by google.

the class TestUtil method createPrimitiveSet.

/**
 * @return a {@code PrimitiveSet} from a {@code KeySet}
 */
public static <P> PrimitiveSet<P> createPrimitiveSet(Keyset keyset, Class<P> inputClass) throws GeneralSecurityException {
    PrimitiveSet<P> primitives = PrimitiveSet.newPrimitiveSet(inputClass);
    for (Keyset.Key key : keyset.getKeyList()) {
        if (key.getStatus() == KeyStatusType.ENABLED) {
            P primitive = Registry.getPrimitive(key.getKeyData(), inputClass);
            PrimitiveSet.Entry<P> entry = primitives.addPrimitive(primitive, key);
            if (key.getKeyId() == keyset.getPrimaryKeyId()) {
                primitives.setPrimary(entry);
            }
        }
    }
    return primitives;
}
Also used : Keyset(com.google.crypto.tink.proto.Keyset) Key(com.google.crypto.tink.proto.Keyset.Key) PrimitiveSet(com.google.crypto.tink.PrimitiveSet)

Aggregations

PrimitiveSet (com.google.crypto.tink.PrimitiveSet)1 Keyset (com.google.crypto.tink.proto.Keyset)1 Key (com.google.crypto.tink.proto.Keyset.Key)1