001/* 002 * Copyright 2018 Paul Schaub. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.pgpainless.key.generation; 017 018import javax.annotation.Nonnull; 019import javax.annotation.Nullable; 020 021import org.bouncycastle.openpgp.PGPSignatureSubpacketGenerator; 022import org.bouncycastle.openpgp.PGPSignatureSubpacketVector; 023import org.pgpainless.key.generation.type.KeyType; 024 025public class KeySpec { 026 027 private final KeyType keyType; 028 private final PGPSignatureSubpacketGenerator subpacketGenerator; 029 private final boolean inheritedSubPackets; 030 031 KeySpec(@Nonnull KeyType type, 032 @Nullable PGPSignatureSubpacketGenerator subpacketGenerator, 033 boolean inheritedSubPackets) { 034 this.keyType = type; 035 this.subpacketGenerator = subpacketGenerator; 036 this.inheritedSubPackets = inheritedSubPackets; 037 } 038 039 @Nonnull 040 KeyType getKeyType() { 041 return keyType; 042 } 043 044 @Nullable 045 PGPSignatureSubpacketVector getSubpackets() { 046 return subpacketGenerator != null ? subpacketGenerator.generate() : null; 047 } 048 049 boolean isInheritedSubPackets() { 050 return inheritedSubPackets; 051 } 052 053 public static KeySpecBuilder getBuilder(KeyType type) { 054 return new KeySpecBuilder(type); 055 } 056}