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