• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2022 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 ////////////////////////////////////////////////////////////////////////////////
16 
17 package com.google.crypto.tink.internal;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 import static java.nio.charset.StandardCharsets.UTF_8;
21 import static org.junit.Assert.assertThrows;
22 
23 import com.google.crypto.tink.InsecureSecretKeyAccess;
24 import com.google.crypto.tink.Key;
25 import com.google.crypto.tink.Parameters;
26 import com.google.crypto.tink.SecretKeyAccess;
27 import com.google.crypto.tink.proto.KeyData.KeyMaterialType;
28 import com.google.crypto.tink.proto.OutputPrefixType;
29 import com.google.crypto.tink.proto.TestProto;
30 import com.google.crypto.tink.util.Bytes;
31 import com.google.errorprone.annotations.Immutable;
32 import com.google.protobuf.ByteString;
33 import java.security.GeneralSecurityException;
34 import javax.annotation.Nullable;
35 import org.junit.Test;
36 import org.junit.runner.RunWith;
37 import org.junit.runners.JUnit4;
38 
39 /**
40  * Tests for {@link MutableSerializationRegistry}.
41  *
42  * <p>We repeat the main tests in SerializationRegistryTest. There really shouldn't be both classes,
43  * but currently this is what we need, and the other is what we should have.
44  */
45 @RunWith(JUnit4.class)
46 public final class MutableSerializationRegistryTest {
47   private static final SecretKeyAccess ACCESS = InsecureSecretKeyAccess.get();
48 
49   private static final Bytes A_1 = Bytes.copyFrom("0".getBytes(UTF_8));
50   private static final Bytes A_2 = Bytes.copyFrom("1".getBytes(UTF_8));
51   private static final Bytes B_1 = Bytes.copyFrom("1".getBytes(UTF_8));
52   private static final Bytes B_2 = Bytes.copyFrom("2".getBytes(UTF_8));
53 
54   @Immutable
55   private static final class TestParameters1 extends Parameters {
56     @Override
hasIdRequirement()57     public boolean hasIdRequirement() {
58       return false;
59     }
60   }
61 
62   @Immutable
63   private static final class TestParameters2 extends Parameters {
64     @Override
hasIdRequirement()65     public boolean hasIdRequirement() {
66       return false;
67     }
68   }
69 
70   @Immutable
71   private static final class TestKey1 extends Key {
72     @Override
getParameters()73     public Parameters getParameters() {
74       throw new UnsupportedOperationException("Not needed in test");
75     }
76 
77     @Override
78     @Nullable
getIdRequirementOrNull()79     public Integer getIdRequirementOrNull() {
80       throw new UnsupportedOperationException("Not needed in test");
81     }
82 
83     @Override
equalsKey(Key other)84     public boolean equalsKey(Key other) {
85       throw new UnsupportedOperationException("Not needed in test");
86     }
87   }
88 
89   @Immutable
90   private static final class TestKey2 extends Key {
91     @Override
getParameters()92     public Parameters getParameters() {
93       throw new UnsupportedOperationException("Not needed in test");
94     }
95 
96     @Override
97     @Nullable
getIdRequirementOrNull()98     public Integer getIdRequirementOrNull() {
99       throw new UnsupportedOperationException("Not needed in test");
100     }
101 
102     @Override
equalsKey(Key other)103     public boolean equalsKey(Key other) {
104       throw new UnsupportedOperationException("Not needed in test");
105     }
106   }
107 
108   @Immutable
109   private static final class TestSerializationA implements Serialization {
TestSerializationA(Bytes objectIdentifier)110     public TestSerializationA(Bytes objectIdentifier) {
111       this.objectIdentifier = objectIdentifier;
112     }
113 
114     private final Bytes objectIdentifier;
115 
116     @Override
getObjectIdentifier()117     public Bytes getObjectIdentifier() {
118       return objectIdentifier;
119     }
120   }
121 
122   @Immutable
123   private static final class TestSerializationB implements Serialization {
TestSerializationB(Bytes objectIdentifier)124     public TestSerializationB(Bytes objectIdentifier) {
125       this.objectIdentifier = objectIdentifier;
126     }
127 
128     private final Bytes objectIdentifier;
129 
130     @Override
getObjectIdentifier()131     public Bytes getObjectIdentifier() {
132       return objectIdentifier;
133     }
134   }
135 
serializeKey1ToA(TestKey1 key, @Nullable SecretKeyAccess access)136   private static TestSerializationA serializeKey1ToA(TestKey1 key, @Nullable SecretKeyAccess access)
137       throws GeneralSecurityException {
138     SecretKeyAccess.requireAccess(access);
139     return new TestSerializationA(A_1);
140   }
141 
serializeKey2ToA(TestKey2 key, @Nullable SecretKeyAccess access)142   private static TestSerializationA serializeKey2ToA(TestKey2 key, @Nullable SecretKeyAccess access)
143       throws GeneralSecurityException {
144     SecretKeyAccess.requireAccess(access);
145     return new TestSerializationA(A_2);
146   }
147 
serializeKey1ToB(TestKey1 key, @Nullable SecretKeyAccess access)148   private static TestSerializationB serializeKey1ToB(TestKey1 key, @Nullable SecretKeyAccess access)
149       throws GeneralSecurityException {
150     SecretKeyAccess.requireAccess(access);
151     return new TestSerializationB(B_1);
152   }
153 
serializeKey2ToB(TestKey2 key, @Nullable SecretKeyAccess access)154   private static TestSerializationB serializeKey2ToB(TestKey2 key, @Nullable SecretKeyAccess access)
155       throws GeneralSecurityException {
156     SecretKeyAccess.requireAccess(access);
157     return new TestSerializationB(B_2);
158   }
159 
parseAToKey1( TestSerializationA serialization, @Nullable SecretKeyAccess access)160   private static Key parseAToKey1(
161       TestSerializationA serialization, @Nullable SecretKeyAccess access)
162       throws GeneralSecurityException {
163     if (!A_1.equals(serialization.getObjectIdentifier())) {
164       throw new GeneralSecurityException("Wrong object identifier");
165     }
166     SecretKeyAccess.requireAccess(access);
167     return new TestKey1();
168   }
169 
parseAToKey2( TestSerializationA serialization, @Nullable SecretKeyAccess access)170   private static Key parseAToKey2(
171       TestSerializationA serialization, @Nullable SecretKeyAccess access)
172       throws GeneralSecurityException {
173     if (!A_2.equals(serialization.getObjectIdentifier())) {
174       throw new GeneralSecurityException("Wrong object identifier");
175     }
176     SecretKeyAccess.requireAccess(access);
177     return new TestKey2();
178   }
179 
parseBToKey1( TestSerializationB serialization, @Nullable SecretKeyAccess access)180   private static Key parseBToKey1(
181       TestSerializationB serialization, @Nullable SecretKeyAccess access)
182       throws GeneralSecurityException {
183     if (!B_1.equals(serialization.getObjectIdentifier())) {
184       throw new GeneralSecurityException("Wrong object identifier");
185     }
186     SecretKeyAccess.requireAccess(access);
187     return new TestKey1();
188   }
189 
parseBToKey2( TestSerializationB serialization, @Nullable SecretKeyAccess access)190   private static Key parseBToKey2(
191       TestSerializationB serialization, @Nullable SecretKeyAccess access)
192       throws GeneralSecurityException {
193     if (!B_2.equals(serialization.getObjectIdentifier())) {
194       throw new GeneralSecurityException("Wrong object identifier");
195     }
196     SecretKeyAccess.requireAccess(access);
197     return new TestKey2();
198   }
199 
200   // ======================================================================= Key serialization tests
201   @Test
test_registerAllSerializers_checkDispatch()202   public void test_registerAllSerializers_checkDispatch() throws Exception {
203     MutableSerializationRegistry registry = new MutableSerializationRegistry();
204     registry.registerKeySerializer(
205         KeySerializer.create(
206             MutableSerializationRegistryTest::serializeKey1ToA,
207             TestKey1.class,
208             TestSerializationA.class));
209     registry.registerKeySerializer(
210         KeySerializer.create(
211             MutableSerializationRegistryTest::serializeKey1ToB,
212             TestKey1.class,
213             TestSerializationB.class));
214     registry.registerKeySerializer(
215         KeySerializer.create(
216             MutableSerializationRegistryTest::serializeKey2ToA,
217             TestKey2.class,
218             TestSerializationA.class));
219     registry.registerKeySerializer(
220         KeySerializer.create(
221             MutableSerializationRegistryTest::serializeKey2ToB,
222             TestKey2.class,
223             TestSerializationB.class));
224     assertThat(registry.hasSerializerForKey(new TestKey1(), TestSerializationA.class)).isTrue();
225     assertThat(
226             registry
227                 .serializeKey(new TestKey1(), TestSerializationA.class, ACCESS)
228                 .getObjectIdentifier())
229         .isEqualTo(A_1);
230     assertThat(
231             registry
232                 .serializeKey(new TestKey2(), TestSerializationA.class, ACCESS)
233                 .getObjectIdentifier())
234         .isEqualTo(A_2);
235     assertThat(
236             registry
237                 .serializeKey(new TestKey1(), TestSerializationB.class, ACCESS)
238                 .getObjectIdentifier())
239         .isEqualTo(B_1);
240     assertThat(
241             registry
242                 .serializeKey(new TestKey2(), TestSerializationB.class, ACCESS)
243                 .getObjectIdentifier())
244         .isEqualTo(B_2);
245   }
246 
247   @Test
emptyRegistry_serializeKey_throws()248   public void emptyRegistry_serializeKey_throws() throws Exception {
249     MutableSerializationRegistry registry = new MutableSerializationRegistry();
250     assertThat(registry.hasSerializerForKey(new TestKey1(), TestSerializationA.class)).isFalse();
251     assertThrows(
252         GeneralSecurityException.class,
253         () -> registry
254                 .serializeKey(new TestKey1(), TestSerializationA.class, ACCESS));
255   }
256 
257   @Test
test_registerAllParsers_checkDispatch()258   public void test_registerAllParsers_checkDispatch() throws Exception {
259     MutableSerializationRegistry registry = new MutableSerializationRegistry();
260     registry.registerKeyParser(
261         KeyParser.create(
262             MutableSerializationRegistryTest::parseAToKey1, A_1, TestSerializationA.class));
263     registry.registerKeyParser(
264         KeyParser.create(
265             MutableSerializationRegistryTest::parseBToKey1, B_1, TestSerializationB.class));
266     registry.registerKeyParser(
267         KeyParser.create(
268             MutableSerializationRegistryTest::parseAToKey2, A_2, TestSerializationA.class));
269     registry.registerKeyParser(
270         KeyParser.create(
271             MutableSerializationRegistryTest::parseBToKey2, B_2, TestSerializationB.class));
272     assertThat(registry.hasParserForKey(new TestSerializationA(A_1))).isTrue();
273     assertThat(registry.parseKey(new TestSerializationA(A_1), ACCESS)).isInstanceOf(TestKey1.class);
274     assertThat(registry.parseKey(new TestSerializationA(A_2), ACCESS)).isInstanceOf(TestKey2.class);
275     assertThat(registry.parseKey(new TestSerializationB(B_1), ACCESS)).isInstanceOf(TestKey1.class);
276     assertThat(registry.parseKey(new TestSerializationB(B_2), ACCESS)).isInstanceOf(TestKey2.class);
277   }
278 
279   @Test
emptyRegistry_parseKey_throws()280   public void emptyRegistry_parseKey_throws() throws Exception {
281     MutableSerializationRegistry registry = new MutableSerializationRegistry();
282     assertThat(registry.hasParserForKey(new TestSerializationA(A_1))).isFalse();
283     assertThrows(
284         GeneralSecurityException.class,
285         () -> registry.parseKey(new TestSerializationA(A_1), ACCESS));
286   }
287 
288   // ================================================================================================
289   // PARAMETERS TESTS
290   // ================================================================================================
serializeParameters1ToA(TestParameters1 parameters)291   private static TestSerializationA serializeParameters1ToA(TestParameters1 parameters)
292       throws GeneralSecurityException {
293     return new TestSerializationA(A_1);
294   }
295 
serializeParameters2ToA(TestParameters2 parameters)296   private static TestSerializationA serializeParameters2ToA(TestParameters2 parameters)
297       throws GeneralSecurityException {
298     return new TestSerializationA(A_2);
299   }
300 
serializeParameters1ToB(TestParameters1 parameters)301   private static TestSerializationB serializeParameters1ToB(TestParameters1 parameters)
302       throws GeneralSecurityException {
303     return new TestSerializationB(B_1);
304   }
305 
serializeParameters2ToB(TestParameters2 parameters)306   private static TestSerializationB serializeParameters2ToB(TestParameters2 parameters)
307       throws GeneralSecurityException {
308     return new TestSerializationB(B_2);
309   }
310 
parseAToParameters1(TestSerializationA serialization)311   private static Parameters parseAToParameters1(TestSerializationA serialization)
312       throws GeneralSecurityException {
313     if (!A_1.equals(serialization.getObjectIdentifier())) {
314       throw new GeneralSecurityException("Wrong object identifier");
315     }
316     return new TestParameters1();
317   }
318 
parseAToParameters2(TestSerializationA serialization)319   private static Parameters parseAToParameters2(TestSerializationA serialization)
320       throws GeneralSecurityException {
321     if (!A_2.equals(serialization.getObjectIdentifier())) {
322       throw new GeneralSecurityException("Wrong object identifier");
323     }
324     return new TestParameters2();
325   }
326 
parseBToParameters1(TestSerializationB serialization)327   private static Parameters parseBToParameters1(TestSerializationB serialization)
328       throws GeneralSecurityException {
329     if (!B_1.equals(serialization.getObjectIdentifier())) {
330       throw new GeneralSecurityException("Wrong object identifier");
331     }
332     return new TestParameters1();
333   }
334 
parseBToParameters2(TestSerializationB serialization)335   private static Parameters parseBToParameters2(TestSerializationB serialization)
336       throws GeneralSecurityException {
337     if (!B_2.equals(serialization.getObjectIdentifier())) {
338       throw new GeneralSecurityException("Wrong object identifier");
339     }
340     return new TestParameters2();
341   }
342 
343   @Test
test_registerAllParametersSerializers_checkDispatch()344   public void test_registerAllParametersSerializers_checkDispatch() throws Exception {
345     MutableSerializationRegistry registry = new MutableSerializationRegistry();
346     registry.registerParametersSerializer(
347         ParametersSerializer.create(
348             MutableSerializationRegistryTest::serializeParameters1ToA,
349             TestParameters1.class,
350             TestSerializationA.class));
351     registry.registerParametersSerializer(
352         ParametersSerializer.create(
353             MutableSerializationRegistryTest::serializeParameters1ToB,
354             TestParameters1.class,
355             TestSerializationB.class));
356     registry.registerParametersSerializer(
357         ParametersSerializer.create(
358             MutableSerializationRegistryTest::serializeParameters2ToA,
359             TestParameters2.class,
360             TestSerializationA.class));
361     registry.registerParametersSerializer(
362         ParametersSerializer.create(
363             MutableSerializationRegistryTest::serializeParameters2ToB,
364             TestParameters2.class,
365             TestSerializationB.class));
366     assertThat(registry.hasSerializerForParameters(new TestParameters1(), TestSerializationA.class))
367         .isTrue();
368     assertThat(
369             registry
370                 .serializeParameters(new TestParameters1(), TestSerializationA.class)
371                 .getObjectIdentifier())
372         .isEqualTo(A_1);
373     assertThat(
374             registry
375                 .serializeParameters(new TestParameters2(), TestSerializationA.class)
376                 .getObjectIdentifier())
377         .isEqualTo(A_2);
378     assertThat(
379             registry
380                 .serializeParameters(new TestParameters1(), TestSerializationB.class)
381                 .getObjectIdentifier())
382         .isEqualTo(B_1);
383     assertThat(
384             registry
385                 .serializeParameters(new TestParameters2(), TestSerializationB.class)
386                 .getObjectIdentifier())
387         .isEqualTo(B_2);
388   }
389 
390   @Test
emptyRegistry_serializeParameters_throws()391   public void emptyRegistry_serializeParameters_throws() throws Exception {
392     MutableSerializationRegistry registry = new MutableSerializationRegistry();
393     assertThat(registry.hasSerializerForParameters(new TestParameters1(), TestSerializationA.class))
394         .isFalse();
395     assertThrows(
396         GeneralSecurityException.class,
397         () -> registry.serializeParameters(new TestParameters1(), TestSerializationA.class));
398   }
399 
400   @Test
test_registerAllParametersParsers_checkDispatch()401   public void test_registerAllParametersParsers_checkDispatch() throws Exception {
402     MutableSerializationRegistry registry = new MutableSerializationRegistry();
403     registry.registerParametersParser(
404         ParametersParser.create(
405             MutableSerializationRegistryTest::parseAToParameters1, A_1, TestSerializationA.class));
406     registry.registerParametersParser(
407         ParametersParser.create(
408             MutableSerializationRegistryTest::parseBToParameters1, B_1, TestSerializationB.class));
409     registry.registerParametersParser(
410         ParametersParser.create(
411             MutableSerializationRegistryTest::parseAToParameters2, A_2, TestSerializationA.class));
412     registry.registerParametersParser(
413         ParametersParser.create(
414             MutableSerializationRegistryTest::parseBToParameters2, B_2, TestSerializationB.class));
415     assertThat(registry.hasParserForParameters(new TestSerializationA(A_1))).isTrue();
416     assertThat(registry.parseParameters(new TestSerializationA(A_1)))
417         .isInstanceOf(TestParameters1.class);
418     assertThat(registry.parseParameters(new TestSerializationA(A_2)))
419         .isInstanceOf(TestParameters2.class);
420     assertThat(registry.parseParameters(new TestSerializationB(B_1)))
421         .isInstanceOf(TestParameters1.class);
422     assertThat(registry.parseParameters(new TestSerializationB(B_2)))
423         .isInstanceOf(TestParameters2.class);
424   }
425 
426   @Test
emptyRegistry_parseParameters_throws()427   public void emptyRegistry_parseParameters_throws() throws Exception {
428     MutableSerializationRegistry registry = new MutableSerializationRegistry();
429     assertThat(registry.hasParserForParameters(new TestSerializationA(A_1))).isFalse();
430     assertThrows(
431         GeneralSecurityException.class,
432         () -> registry.parseParameters(new TestSerializationA(A_1)));
433   }
434 
435   @Test
test_parseParametersWithLegacyFallback_testFallback()436   public void test_parseParametersWithLegacyFallback_testFallback() throws Exception {
437     MutableSerializationRegistry registry = new MutableSerializationRegistry();
438     ProtoParametersSerialization protoParameters =
439         ProtoParametersSerialization.create(
440             "typeUrlForTesting73107", OutputPrefixType.TINK, TestProto.getDefaultInstance());
441     Parameters parameters = registry.parseParametersWithLegacyFallback(protoParameters);
442     assertThat(parameters).isInstanceOf(LegacyProtoParameters.class);
443     LegacyProtoParameters legacyProtoParameters = (LegacyProtoParameters) parameters;
444     assertThat(legacyProtoParameters.getSerialization().getKeyTemplate().getTypeUrl())
445         .isEqualTo("typeUrlForTesting73107");
446   }
447 
parseParameters(ProtoParametersSerialization serialization)448   private static TestParameters1 parseParameters(ProtoParametersSerialization serialization)
449       throws GeneralSecurityException {
450     return new TestParameters1();
451   }
452 
parseParametersAlwaysThrows( ProtoParametersSerialization serialization)453   private static TestParameters1 parseParametersAlwaysThrows(
454       ProtoParametersSerialization serialization) throws GeneralSecurityException {
455     throw new GeneralSecurityException("Always throws");
456   }
457 
458   @Test
test_parseParametersWithLegacyFallback_testRegistered()459   public void test_parseParametersWithLegacyFallback_testRegistered() throws Exception {
460     MutableSerializationRegistry registry = new MutableSerializationRegistry();
461     registry.registerParametersParser(
462         ParametersParser.create(
463             MutableSerializationRegistryTest::parseParameters,
464             Util.toBytesFromPrintableAscii("typeUrlForTesting98178"),
465             ProtoParametersSerialization.class));
466     ProtoParametersSerialization protoParameters =
467         ProtoParametersSerialization.create(
468             "typeUrlForTesting98178", OutputPrefixType.TINK, TestProto.getDefaultInstance());
469     Parameters parameters = registry.parseParametersWithLegacyFallback(protoParameters);
470     assertThat(parameters).isInstanceOf(TestParameters1.class);
471   }
472 
473   @Test
test_parseParametersWithLegacyFallback_testRegisteredButFaulty_throws()474   public void test_parseParametersWithLegacyFallback_testRegisteredButFaulty_throws()
475       throws Exception {
476     MutableSerializationRegistry registry = new MutableSerializationRegistry();
477     registry.registerParametersParser(
478         ParametersParser.create(
479             MutableSerializationRegistryTest::parseParametersAlwaysThrows,
480             Util.toBytesFromPrintableAscii("typeUrlForTesting98178"),
481             ProtoParametersSerialization.class));
482     ProtoParametersSerialization protoParameters =
483         ProtoParametersSerialization.create(
484             "typeUrlForTesting98178", OutputPrefixType.TINK, TestProto.getDefaultInstance());
485     assertThrows(
486         GeneralSecurityException.class,
487         () -> registry.parseParametersWithLegacyFallback(protoParameters));
488   }
489 
490   @Test
test_parseKeyWithLegacyFallback_testFallback()491   public void test_parseKeyWithLegacyFallback_testFallback() throws Exception {
492     MutableSerializationRegistry registry = new MutableSerializationRegistry();
493     ProtoKeySerialization protoKey =
494         ProtoKeySerialization.create(
495             "typeUrlForTesting21125",
496             ByteString.EMPTY,
497             KeyMaterialType.SYMMETRIC,
498             OutputPrefixType.RAW,
499             /* idRequirement= */ null);
500     Key key = registry.parseKeyWithLegacyFallback(protoKey, InsecureSecretKeyAccess.get());
501     assertThat(key).isInstanceOf(LegacyProtoKey.class);
502     LegacyProtoKey legacyProtoKey = (LegacyProtoKey) key;
503     assertThat(legacyProtoKey.getSerialization(InsecureSecretKeyAccess.get()).getTypeUrl())
504         .isEqualTo("typeUrlForTesting21125");
505   }
506 
parseKey( ProtoKeySerialization serialization, @Nullable SecretKeyAccess access)507   private static TestKey1 parseKey(
508       ProtoKeySerialization serialization, @Nullable SecretKeyAccess access)
509       throws GeneralSecurityException {
510     return new TestKey1();
511   }
512 
513   @Test
test_parseKeyWithLegacyFallback_testRegistered()514   public void test_parseKeyWithLegacyFallback_testRegistered() throws Exception {
515     MutableSerializationRegistry registry = new MutableSerializationRegistry();
516     registry.registerKeyParser(
517         KeyParser.create(
518             MutableSerializationRegistryTest::parseKey,
519             Util.toBytesFromPrintableAscii("typeUrlForTesting18412"),
520             ProtoKeySerialization.class));
521     ProtoKeySerialization protoKey =
522         ProtoKeySerialization.create(
523             "typeUrlForTesting18412",
524             ByteString.EMPTY,
525             KeyMaterialType.SYMMETRIC,
526             OutputPrefixType.RAW,
527             /* idRequirement= */ null);
528     Key key = registry.parseKeyWithLegacyFallback(protoKey, InsecureSecretKeyAccess.get());
529     assertThat(key).isInstanceOf(TestKey1.class);
530   }
531 
532   @Test
test_parseKeyWithLegacyFallback_testFallback_missingAccess()533   public void test_parseKeyWithLegacyFallback_testFallback_missingAccess() throws Exception {
534     MutableSerializationRegistry registry = new MutableSerializationRegistry();
535     ProtoKeySerialization protoKey =
536         ProtoKeySerialization.create(
537             "typeUrlForTesting21125",
538             ByteString.EMPTY,
539             KeyMaterialType.SYMMETRIC,
540             OutputPrefixType.RAW,
541             /* idRequirement= */ null);
542     assertThrows(
543         GeneralSecurityException.class, () -> registry.parseKeyWithLegacyFallback(protoKey, null));
544   }
545 
546   @Test
test_parseKeyWithLegacyFallback_testFallback_accessNotNeededRemote()547   public void test_parseKeyWithLegacyFallback_testFallback_accessNotNeededRemote()
548       throws Exception {
549     MutableSerializationRegistry registry = new MutableSerializationRegistry();
550     ProtoKeySerialization protoKey =
551         ProtoKeySerialization.create(
552             "typeUrlForTesting21125",
553             ByteString.EMPTY,
554             KeyMaterialType.REMOTE,
555             OutputPrefixType.RAW,
556             /* idRequirement= */ null);
557     Key key = registry.parseKeyWithLegacyFallback(protoKey, InsecureSecretKeyAccess.get());
558     assertThat(key).isInstanceOf(LegacyProtoKey.class);
559   }
560 }
561