• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2024 Google Inc.
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 
21 import com.google.crypto.tink.util.Bytes;
22 import org.junit.Test;
23 import org.junit.runner.RunWith;
24 import org.junit.runners.JUnit4;
25 
26 @RunWith(JUnit4.class)
27 public final class OutputPrefixUtilTest {
28 
29   @Test
getTinkOutputPrefix_works()30   public void getTinkOutputPrefix_works() {
31     Bytes prefix = OutputPrefixUtil.getTinkOutputPrefix(0x12345678);
32     assertThat(prefix)
33         .isEqualTo(
34             Bytes.copyFrom(
35                 new byte[] {(byte) 0x01, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78}));
36     assertThat(prefix.size()).isEqualTo(OutputPrefixUtil.NON_EMPTY_PREFIX_SIZE);
37   }
38 
39   @Test
getLegacyOutputPrefix_works()40   public void getLegacyOutputPrefix_works() {
41     Bytes prefix = OutputPrefixUtil.getLegacyOutputPrefix(0x12345678);
42     assertThat(prefix)
43         .isEqualTo(
44             Bytes.copyFrom(
45                 new byte[] {(byte) 0x00, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78}));
46     assertThat(prefix.size()).isEqualTo(OutputPrefixUtil.NON_EMPTY_PREFIX_SIZE);
47   }
48 
49   @Test
emptyPrefix_isEmpty()50   public void emptyPrefix_isEmpty() {
51     assertThat(OutputPrefixUtil.EMPTY_PREFIX).isEqualTo(Bytes.copyFrom(new byte[] {}));
52   }
53 }
54