xref: /aosp_15_r20/external/tink/java_src/src/main/java/com/google/crypto/tink/signature/SignaturePrivateKey.java (revision e7b1675dde1b92d52ec075b0a92829627f2c52a5)
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.signature;
18 
19 import com.google.crypto.tink.Key;
20 import com.google.crypto.tink.PrivateKey;
21 import com.google.crypto.tink.annotations.Alpha;
22 import com.google.crypto.tink.util.Bytes;
23 import com.google.errorprone.annotations.Immutable;
24 import javax.annotation.Nullable;
25 
26 /**
27  * A {@link SignaturePrivateKey} represents a digital signature primitive, which consists of a sign
28  * and a verify function.
29  *
30  * <p>The verify function is only available indirectly, with {@link #getPublicKey}.
31  */
32 @Immutable
33 @Alpha
34 public abstract class SignaturePrivateKey extends Key implements PrivateKey {
35   /**
36    * Returns the {@link SignaturePublicKey}, which contains the verify function of the digital
37    * signature primitive.
38    */
39   @Override
getPublicKey()40   public abstract SignaturePublicKey getPublicKey();
41 
42   /**
43    * Returns a {@link Bytes} instance which is prefixed to every signature.
44    *
45    * <p>Returns the same as {@code getPublicKey().getOutputPrefix()}.
46    */
getOutputPrefix()47   public final Bytes getOutputPrefix() {
48     return getPublicKey().getOutputPrefix();
49   }
50 
51   @Override
52   @Nullable
getIdRequirementOrNull()53   public Integer getIdRequirementOrNull() {
54     return getPublicKey().getIdRequirementOrNull();
55   }
56 
57   /**
58    * Returns the parameters of this key.
59    *
60    * <p>Returns the same as {@code getPublicKey().getParameters()}.
61    */
62   @Override
getParameters()63   public SignatureParameters getParameters() {
64     return getPublicKey().getParameters();
65   }
66 }
67