CleartextKeysetHandle { public static KeysetHandle read(KeysetReader reader) throws GeneralSecurityException, IOException { return KeysetHandle.fromKeyset(reader.read()); }  @Deprecated static final KeysetHandle parseFrom(final byte[] serialized); static KeysetHandle read(KeysetReader reader); static Keyset getKeyset(KeysetHandle keysetHandle); static KeysetHandle fromKeyset(Keyset keyset); static void write(KeysetHandle handle, KeysetWriter keysetWriter);  }
@Test public void testRead() throws Exception { KeyTemplate template = MacKeyTemplates.HMAC_SHA256_128BITTAG; KeysetManager manager = KeysetManager.withEmptyKeyset().rotate(template); Keyset keyset1 = manager.getKeysetHandle().getKeyset(); KeysetHandle handle1 = CleartextKeysetHandle.read(BinaryKeysetReader.withBytes(keyset1.toByteArray())); assertEquals(keyset1, handle1.getKeyset()); KeysetHandle handle2 = KeysetHandle.generateNew(template); Keyset keyset2 = handle2.getKeyset(); assertEquals(1, keyset2.getKeyCount()); Keyset.Key key2 = keyset2.getKey(0); assertEquals(keyset2.getPrimaryKeyId(), key2.getKeyId()); assertEquals(template.getTypeUrl(), key2.getKeyData().getTypeUrl()); Mac unused = handle2.getPrimitive(Mac.class); }