1 // Copyright 2020 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 package com.google.crypto.tink.tinkkey; 17 18 import com.google.crypto.tink.KeyTemplate; 19 import com.google.errorprone.annotations.Immutable; 20 21 /** 22 * {@code TinkKey} represents how Tink views individual keys. In contrast, {@code KeysetHandle} only 23 * provides access to a {@code Keyset}, which represents multiple keys. 24 * 25 * <p>A {@code TinkKey} contains the data associated to a type of key and provides ways of getting 26 * that data. The {@code TinkKey} interface does not specify how the key data is represented nor how 27 * it provides access to the data. 28 * 29 * <p>Do not use this in new code. Instead, use {@link com.google.crypto.tink.Key}. 30 */ 31 @Immutable 32 public interface TinkKey { 33 /** Returns true if the key contains secret key material, and false otherwise. */ hasSecret()34 public boolean hasSecret(); 35 36 /** 37 * A {@code TinkKey} should know the {@code KeyTemplate} from which it was generated, 38 * which in turn specifies the cryptographic algorithm in which the {@code TinkKey} should 39 * be used. 40 * 41 * Throws UnsupportedOperationException to help ease rollout until it is possible to easily 42 * find the KeyTemplate associated to a key described in proto 43 * 44 * @return the {@code KeyTemplate} used to generate the key. 45 * @throws UnsupportedOperationException if the {@code TinkKey} does not yet support returning 46 * its {@code KeyTemplate} 47 **/ 48 getKeyTemplate()49 public KeyTemplate getKeyTemplate(); 50 } 51