// Copyright 2017 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////////

package com.google.crypto.tink;

import com.google.crypto.tink.proto.Keyset;
import com.google.protobuf.ExtensionRegistryLite;
import com.google.protobuf.InvalidProtocolBufferException;
import java.io.IOException;
import java.security.GeneralSecurityException;

Static methods for reading or writing cleartext keysets.

WARNING

Reading or writing cleartext keysets is a bad practice, usage of this API should be restricted. Users can read encrypted keysets using read.read.

Since:1.0.0
/** * Static methods for reading or writing cleartext keysets. * * <h3>WARNING</h3> * * <p>Reading or writing cleartext keysets is a bad practice, usage of this API should be * restricted. Users can read encrypted keysets using {@link KeysetHandle#read}. * * @since 1.0.0 */
public final class CleartextKeysetHandle {
Throws:
Returns:a new KeysetHandle from serialized that is a serialized Keyset
Deprecated:use read instead
/** * @return a new {@link KeysetHandle} from {@code serialized} that is a serialized {@link Keyset} * @throws GeneralSecurityException * @deprecated use {@link #read} instead */
@Deprecated public static final KeysetHandle parseFrom(final byte[] serialized) throws GeneralSecurityException { try { Keyset keyset = Keyset.parseFrom(serialized, ExtensionRegistryLite.getEmptyRegistry()); return KeysetHandle.fromKeyset(keyset); } catch (InvalidProtocolBufferException e) { throw new GeneralSecurityException("invalid keyset"); } }
Throws:
Returns:a new KeysetHandle from a Keyset read with reader.
/** * @return a new {@link KeysetHandle} from a {@link Keyset} read with {@code reader}. * @throws GeneralSecurityException */
public static KeysetHandle read(KeysetReader reader) throws GeneralSecurityException, IOException { return KeysetHandle.fromKeyset(reader.read()); }
Returns:the keyset underlying this keysetHandle.
/** * @return the keyset underlying this {@code keysetHandle}. */
public static Keyset getKeyset(KeysetHandle keysetHandle) { return keysetHandle.getKeyset(); }
Serializes and writes the Keyset managed by handle to keysetWriter.
Throws:
/** * Serializes and writes the {@link Keyset} managed by {@code handle} to {@code keysetWriter}. * * @throws IOException */
public static void write(KeysetHandle handle, KeysetWriter keysetWriter) throws IOException { keysetWriter.write(handle.getKeyset()); } }