View Javadoc
1   /*
2    * GordianKnot: Security Suite
3    * Copyright 2012-2026. Tony Washer
4    *
5    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
6    * use this file except in compliance with the License.  You may obtain a copy
7    * of the License at
8    *
9    *   http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
14   * License for the specific language governing permissions and limitations under
15   * the License.
16   */
17  package io.github.tonywasher.joceanus.gordianknot.api.encrypt;
18  
19  import io.github.tonywasher.joceanus.gordianknot.api.base.GordianException;
20  import io.github.tonywasher.joceanus.gordianknot.api.keypair.GordianKeyPair;
21  import io.github.tonywasher.joceanus.gordianknot.api.keypair.GordianKeyPairSpec;
22  import io.github.tonywasher.joceanus.gordianknot.api.keypair.GordianKeyPairType;
23  
24  import java.util.List;
25  import java.util.function.Predicate;
26  
27  /**
28   * GordianKnot EncryptorFactory API.
29   */
30  public interface GordianEncryptorFactory {
31      /**
32       * Create keyPairEncryptor.
33       *
34       * @param pSpec the encryptorSpec
35       * @return the Encryptor
36       * @throws GordianException on error
37       */
38      GordianEncryptor createEncryptor(GordianEncryptorSpec pSpec) throws GordianException;
39  
40      /**
41       * Obtain predicate for Encryptor.
42       *
43       * @return the predicate
44       */
45      Predicate<GordianEncryptorSpec> supportedEncryptors();
46  
47      /**
48       * Obtain a list of supported encryptorSpecs.
49       *
50       * @param pKeyType the keyType
51       * @return the list of supported encryptorSpecs.
52       */
53      default List<GordianEncryptorSpec> listAllSupportedEncryptors(final GordianKeyPairType pKeyType) {
54          return listPossibleEncryptors(pKeyType)
55                  .stream()
56                  .filter(supportedEncryptors())
57                  .toList();
58      }
59  
60      /**
61       * Check EncryptorSpec and KeyPair combination.
62       *
63       * @param pKeyPair       the keyPair
64       * @param pEncryptorSpec the macSpec
65       * @return true/false
66       */
67      default boolean validEncryptorSpecForKeyPair(final GordianKeyPair pKeyPair,
68                                                   final GordianEncryptorSpec pEncryptorSpec) {
69          return validEncryptorSpecForKeyPairSpec(pKeyPair.getKeyPairSpec(), pEncryptorSpec);
70      }
71  
72      /**
73       * Check EncryptorSpec and KeyPairSpec combination.
74       *
75       * @param pKeyPairSpec   the keyPairSpec
76       * @param pEncryptorSpec the macSpec
77       * @return true/false
78       */
79      boolean validEncryptorSpecForKeyPairSpec(GordianKeyPairSpec pKeyPairSpec,
80                                               GordianEncryptorSpec pEncryptorSpec);
81  
82      /**
83       * Obtain a list of supported encryptorSpecs.
84       *
85       * @param pKeyPair the keyPair
86       * @return the list of supported encryptorSpecs.
87       */
88      List<GordianEncryptorSpec> listAllSupportedEncryptors(GordianKeyPair pKeyPair);
89  
90      /**
91       * Obtain a list of supported encryptorSpecs.
92       *
93       * @param pKeyPairSpec the keySpec
94       * @return the list of supported encryptorSpecs.
95       */
96      List<GordianEncryptorSpec> listAllSupportedEncryptors(GordianKeyPairSpec pKeyPairSpec);
97  
98      /**
99       * Obtain a list of all possible encryptors for the keyType.
100      *
101      * @param pKeyPairType the keyPairType
102      * @return the list
103      */
104     List<GordianEncryptorSpec> listPossibleEncryptors(GordianKeyPairType pKeyPairType);
105 
106     /**
107      * Create default signatureSpec for key.
108      *
109      * @param pKeySpec the keySpec
110      * @return the SignatureSpec
111      */
112     GordianEncryptorSpec defaultForKeyPair(GordianKeyPairSpec pKeySpec);
113 }