001// SPDX-FileCopyrightText: 2018 Paul Schaub <vanitasvitae@fsfe.org> 002// 003// SPDX-License-Identifier: Apache-2.0 004 005package org.pgpainless.key.protection; 006 007import javax.annotation.Nonnull; 008 009import org.pgpainless.algorithm.HashAlgorithm; 010import org.pgpainless.algorithm.SymmetricKeyAlgorithm; 011 012public class KeyRingProtectionSettings { 013 014 private final SymmetricKeyAlgorithm encryptionAlgorithm; 015 private final HashAlgorithm hashAlgorithm; 016 private final int s2kCount; 017 018 public KeyRingProtectionSettings(@Nonnull SymmetricKeyAlgorithm encryptionAlgorithm) { 019 this(encryptionAlgorithm, HashAlgorithm.SHA1, 0x60); // Same s2kCount as used in BC. 020 } 021 022 public KeyRingProtectionSettings(@Nonnull SymmetricKeyAlgorithm encryptionAlgorithm, @Nonnull HashAlgorithm hashAlgorithm, int s2kCount) { 023 this.encryptionAlgorithm = encryptionAlgorithm; 024 this.hashAlgorithm = hashAlgorithm; 025 if (s2kCount < 1) { 026 throw new IllegalArgumentException("s2kCount cannot be less than 1."); 027 } 028 this.s2kCount = s2kCount; 029 } 030 031 public static KeyRingProtectionSettings secureDefaultSettings() { 032 return new KeyRingProtectionSettings(SymmetricKeyAlgorithm.AES_256); 033 } 034 035 public @Nonnull SymmetricKeyAlgorithm getEncryptionAlgorithm() { 036 return encryptionAlgorithm; 037 } 038 039 public @Nonnull HashAlgorithm getHashAlgorithm() { 040 return hashAlgorithm; 041 } 042 043 public int getS2kCount() { 044 return s2kCount; 045 } 046}