Skip to content

Commit ec5226b

Browse files
authored
Add security exception classes (#107)
1 parent 1e35518 commit ec5226b

File tree

4 files changed

+323
-0
lines changed

4 files changed

+323
-0
lines changed

library/core/api/core.klib.api

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,65 @@ abstract interface org.kotlincrypto.core/Updatable { // org.kotlincrypto.core/Up
3131
abstract fun update(kotlin/ByteArray) // org.kotlincrypto.core/Updatable.update|update(kotlin.ByteArray){}[0]
3232
abstract fun update(kotlin/ByteArray, kotlin/Int, kotlin/Int) // org.kotlincrypto.core/Updatable.update|update(kotlin.ByteArray;kotlin.Int;kotlin.Int){}[0]
3333
}
34+
35+
open class org.kotlincrypto.core/BadPaddingException : org.kotlincrypto.core/GeneralSecurityException { // org.kotlincrypto.core/BadPaddingException|null[0]
36+
constructor <init>() // org.kotlincrypto.core/BadPaddingException.<init>|<init>(){}[0]
37+
constructor <init>(kotlin/String?) // org.kotlincrypto.core/BadPaddingException.<init>|<init>(kotlin.String?){}[0]
38+
}
39+
40+
open class org.kotlincrypto.core/CertificateEncodingException : org.kotlincrypto.core/CertificateException { // org.kotlincrypto.core/CertificateEncodingException|null[0]
41+
constructor <init>() // org.kotlincrypto.core/CertificateEncodingException.<init>|<init>(){}[0]
42+
constructor <init>(kotlin/String?) // org.kotlincrypto.core/CertificateEncodingException.<init>|<init>(kotlin.String?){}[0]
43+
constructor <init>(kotlin/String?, kotlin/Throwable?) // org.kotlincrypto.core/CertificateEncodingException.<init>|<init>(kotlin.String?;kotlin.Throwable?){}[0]
44+
constructor <init>(kotlin/Throwable?) // org.kotlincrypto.core/CertificateEncodingException.<init>|<init>(kotlin.Throwable?){}[0]
45+
}
46+
47+
open class org.kotlincrypto.core/CertificateException : org.kotlincrypto.core/GeneralSecurityException { // org.kotlincrypto.core/CertificateException|null[0]
48+
constructor <init>() // org.kotlincrypto.core/CertificateException.<init>|<init>(){}[0]
49+
constructor <init>(kotlin/String?) // org.kotlincrypto.core/CertificateException.<init>|<init>(kotlin.String?){}[0]
50+
constructor <init>(kotlin/String?, kotlin/Throwable?) // org.kotlincrypto.core/CertificateException.<init>|<init>(kotlin.String?;kotlin.Throwable?){}[0]
51+
constructor <init>(kotlin/Throwable?) // org.kotlincrypto.core/CertificateException.<init>|<init>(kotlin.Throwable?){}[0]
52+
}
53+
54+
open class org.kotlincrypto.core/CertificateParsingException : org.kotlincrypto.core/CertificateException { // org.kotlincrypto.core/CertificateParsingException|null[0]
55+
constructor <init>() // org.kotlincrypto.core/CertificateParsingException.<init>|<init>(){}[0]
56+
constructor <init>(kotlin/String?) // org.kotlincrypto.core/CertificateParsingException.<init>|<init>(kotlin.String?){}[0]
57+
constructor <init>(kotlin/String?, kotlin/Throwable?) // org.kotlincrypto.core/CertificateParsingException.<init>|<init>(kotlin.String?;kotlin.Throwable?){}[0]
58+
constructor <init>(kotlin/Throwable?) // org.kotlincrypto.core/CertificateParsingException.<init>|<init>(kotlin.Throwable?){}[0]
59+
}
60+
61+
open class org.kotlincrypto.core/GeneralSecurityException : kotlin/Exception { // org.kotlincrypto.core/GeneralSecurityException|null[0]
62+
constructor <init>() // org.kotlincrypto.core/GeneralSecurityException.<init>|<init>(){}[0]
63+
constructor <init>(kotlin/String?) // org.kotlincrypto.core/GeneralSecurityException.<init>|<init>(kotlin.String?){}[0]
64+
constructor <init>(kotlin/String?, kotlin/Throwable?) // org.kotlincrypto.core/GeneralSecurityException.<init>|<init>(kotlin.String?;kotlin.Throwable?){}[0]
65+
constructor <init>(kotlin/Throwable?) // org.kotlincrypto.core/GeneralSecurityException.<init>|<init>(kotlin.Throwable?){}[0]
66+
}
67+
68+
open class org.kotlincrypto.core/IllegalBlockSizeException : org.kotlincrypto.core/GeneralSecurityException { // org.kotlincrypto.core/IllegalBlockSizeException|null[0]
69+
constructor <init>() // org.kotlincrypto.core/IllegalBlockSizeException.<init>|<init>(){}[0]
70+
constructor <init>(kotlin/String?) // org.kotlincrypto.core/IllegalBlockSizeException.<init>|<init>(kotlin.String?){}[0]
71+
}
72+
73+
open class org.kotlincrypto.core/InvalidKeyException : org.kotlincrypto.core/KeyException { // org.kotlincrypto.core/InvalidKeyException|null[0]
74+
constructor <init>() // org.kotlincrypto.core/InvalidKeyException.<init>|<init>(){}[0]
75+
constructor <init>(kotlin/String?) // org.kotlincrypto.core/InvalidKeyException.<init>|<init>(kotlin.String?){}[0]
76+
constructor <init>(kotlin/String?, kotlin/Throwable?) // org.kotlincrypto.core/InvalidKeyException.<init>|<init>(kotlin.String?;kotlin.Throwable?){}[0]
77+
constructor <init>(kotlin/Throwable?) // org.kotlincrypto.core/InvalidKeyException.<init>|<init>(kotlin.Throwable?){}[0]
78+
}
79+
80+
open class org.kotlincrypto.core/InvalidParameterException : kotlin/IllegalArgumentException { // org.kotlincrypto.core/InvalidParameterException|null[0]
81+
constructor <init>() // org.kotlincrypto.core/InvalidParameterException.<init>|<init>(){}[0]
82+
constructor <init>(kotlin/String?) // org.kotlincrypto.core/InvalidParameterException.<init>|<init>(kotlin.String?){}[0]
83+
}
84+
85+
open class org.kotlincrypto.core/KeyException : org.kotlincrypto.core/GeneralSecurityException { // org.kotlincrypto.core/KeyException|null[0]
86+
constructor <init>() // org.kotlincrypto.core/KeyException.<init>|<init>(){}[0]
87+
constructor <init>(kotlin/String?) // org.kotlincrypto.core/KeyException.<init>|<init>(kotlin.String?){}[0]
88+
constructor <init>(kotlin/String?, kotlin/Throwable?) // org.kotlincrypto.core/KeyException.<init>|<init>(kotlin.String?;kotlin.Throwable?){}[0]
89+
constructor <init>(kotlin/Throwable?) // org.kotlincrypto.core/KeyException.<init>|<init>(kotlin.Throwable?){}[0]
90+
}
91+
92+
open class org.kotlincrypto.core/ShortBufferException : org.kotlincrypto.core/GeneralSecurityException { // org.kotlincrypto.core/ShortBufferException|null[0]
93+
constructor <init>() // org.kotlincrypto.core/ShortBufferException.<init>|<init>(){}[0]
94+
constructor <init>(kotlin/String?) // org.kotlincrypto.core/ShortBufferException.<init>|<init>(kotlin.String?){}[0]
95+
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/*
2+
* Copyright (c) 2025 Matthew Nelson
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
**/
16+
@file:Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING")
17+
18+
package org.kotlincrypto.core
19+
20+
/**
21+
* This exception is thrown when an invalid parameter is encountered.
22+
* */
23+
public expect open class InvalidParameterException: IllegalArgumentException {
24+
public constructor()
25+
public constructor(message: String?)
26+
}
27+
28+
/**
29+
* The `GeneralSecurityException` class is a generic security exception class that provides type
30+
* safety for all the security-related exception classes that extend from it.
31+
* */
32+
public expect open class GeneralSecurityException: Exception {
33+
public constructor()
34+
public constructor(message: String?)
35+
public constructor(message: String?, cause: Throwable?)
36+
public constructor(cause: Throwable?)
37+
}
38+
39+
/**
40+
* This exception is thrown when a particular padding mechanism is expected for the input data but
41+
* the data is not padded properly.
42+
* */
43+
public expect open class BadPaddingException: GeneralSecurityException {
44+
public constructor()
45+
public constructor(message: String?)
46+
}
47+
48+
/**
49+
* The `CertificateException` class is a generic security exception class that provides type safety
50+
* for all the certificate-related exception classes that extend from it.
51+
* */
52+
public expect open class CertificateException: GeneralSecurityException {
53+
public constructor()
54+
public constructor(message: String?)
55+
public constructor(message: String?, cause: Throwable?)
56+
public constructor(cause: Throwable?)
57+
}
58+
59+
/**
60+
* This exception is thrown when an error occurs while attempting to encode a certificate.
61+
* */
62+
public expect open class CertificateEncodingException: CertificateException {
63+
public constructor()
64+
public constructor(message: String?)
65+
public constructor(message: String?, cause: Throwable?)
66+
public constructor(cause: Throwable?)
67+
}
68+
69+
/**
70+
* This exception is thrown whenever an invalid DER-encoded certificate is parsed, or unsupported
71+
* DER features are found in the Certificate.
72+
* */
73+
public expect open class CertificateParsingException: CertificateException {
74+
public constructor()
75+
public constructor(message: String?)
76+
public constructor(message: String?, cause: Throwable?)
77+
public constructor(cause: Throwable?)
78+
}
79+
80+
/**
81+
* This exception is thrown when the length of data provided to a block cipher is incorrect, (i.e.
82+
* does not match the block size of the cipher.)
83+
* */
84+
public expect open class IllegalBlockSizeException: GeneralSecurityException {
85+
public constructor()
86+
public constructor(message: String?)
87+
}
88+
89+
/**
90+
* The `KeyException` class is a generic security exception class that provides type safety for all
91+
* the key-related exception classes that extend from it.
92+
* */
93+
public expect open class KeyException: GeneralSecurityException {
94+
public constructor()
95+
public constructor(message: String?)
96+
public constructor(message: String?, cause: Throwable?)
97+
public constructor(cause: Throwable?)
98+
}
99+
100+
/**
101+
* This exception is thrown when a key is invalid (e.g. invalid encoding, wrong length, etc.).
102+
* */
103+
public expect open class InvalidKeyException: KeyException {
104+
public constructor()
105+
public constructor(message: String?)
106+
public constructor(message: String?, cause: Throwable?)
107+
public constructor(cause: Throwable?)
108+
}
109+
110+
/**
111+
* This exception is thrown when a buffer provided by the user is too short to hold the operation result.
112+
* */
113+
public expect open class ShortBufferException: GeneralSecurityException {
114+
public constructor()
115+
public constructor(message: String?)
116+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) 2025 Matthew Nelson
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
**/
16+
@file:Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING")
17+
18+
package org.kotlincrypto.core
19+
20+
public actual typealias InvalidParameterException = java.security.InvalidParameterException
21+
public actual typealias GeneralSecurityException = java.security.GeneralSecurityException
22+
public actual typealias BadPaddingException = javax.crypto.BadPaddingException
23+
public actual typealias CertificateException = java.security.cert.CertificateException
24+
public actual typealias CertificateEncodingException = java.security.cert.CertificateEncodingException
25+
public actual typealias CertificateParsingException = java.security.cert.CertificateParsingException
26+
public actual typealias IllegalBlockSizeException = javax.crypto.IllegalBlockSizeException
27+
public actual typealias KeyException = java.security.KeyException
28+
public actual typealias InvalidKeyException = java.security.InvalidKeyException
29+
public actual typealias ShortBufferException = javax.crypto.ShortBufferException
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/*
2+
* Copyright (c) 2025 Matthew Nelson
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
**/
16+
@file:Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING")
17+
18+
package org.kotlincrypto.core
19+
20+
/**
21+
* This exception is thrown when an invalid parameter is encountered.
22+
* */
23+
public actual open class InvalidParameterException: IllegalArgumentException {
24+
public actual constructor(): super()
25+
public actual constructor(message: String?): super(message)
26+
}
27+
28+
/**
29+
* The `GeneralSecurityException` class is a generic security exception class that provides type
30+
* safety for all the security-related exception classes that extend from it.
31+
* */
32+
public actual open class GeneralSecurityException: Exception {
33+
public actual constructor(): super()
34+
public actual constructor(message: String?): super(message)
35+
public actual constructor(message: String?, cause: Throwable?): super(message, cause)
36+
public actual constructor(cause: Throwable?): super(cause)
37+
}
38+
39+
/**
40+
* This exception is thrown when a particular padding mechanism is expected for the input data but
41+
* the data is not padded properly.
42+
* */
43+
public actual open class BadPaddingException: GeneralSecurityException {
44+
public actual constructor(): super()
45+
public actual constructor(message: String?): super(message)
46+
}
47+
48+
/**
49+
* The `CertificateException` class is a generic security exception class that provides type safety
50+
* for all the certificate-related exception classes that extend from it.
51+
* */
52+
public actual open class CertificateException: GeneralSecurityException {
53+
public actual constructor(): super()
54+
public actual constructor(message: String?): super(message)
55+
public actual constructor(message: String?, cause: Throwable?): super(message, cause)
56+
public actual constructor(cause: Throwable?): super(cause)
57+
}
58+
59+
/**
60+
* This exception is thrown when an error occurs while attempting to encode a certificate.
61+
* */
62+
public actual open class CertificateEncodingException: CertificateException {
63+
public actual constructor(): super()
64+
public actual constructor(message: String?): super(message)
65+
public actual constructor(message: String?, cause: Throwable?): super(message, cause)
66+
public actual constructor(cause: Throwable?): super(cause)
67+
}
68+
69+
/**
70+
* This exception is thrown whenever an invalid DER-encoded certificate is parsed, or unsupported
71+
* DER features are found in the Certificate.
72+
* */
73+
public actual open class CertificateParsingException: CertificateException {
74+
public actual constructor(): super()
75+
public actual constructor(message: String?): super(message)
76+
public actual constructor(message: String?, cause: Throwable?): super(message, cause)
77+
public actual constructor(cause: Throwable?): super(cause)
78+
}
79+
80+
/**
81+
* This exception is thrown when the length of data provided to a block cipher is incorrect, (i.e.
82+
* does not match the block size of the cipher.)
83+
* */
84+
public actual open class IllegalBlockSizeException: GeneralSecurityException {
85+
public actual constructor(): super()
86+
public actual constructor(message: String?): super(message)
87+
}
88+
89+
/**
90+
* The `KeyException` class is a generic security exception class that provides type safety for all
91+
* the key-related exception classes that extend from it.
92+
* */
93+
public actual open class KeyException: GeneralSecurityException {
94+
public actual constructor(): super()
95+
public actual constructor(message: String?): super(message)
96+
public actual constructor(message: String?, cause: Throwable?): super(message, cause)
97+
public actual constructor(cause: Throwable?): super(cause)
98+
}
99+
100+
/**
101+
* This exception is thrown when a key is invalid (e.g. invalid encoding, wrong length, etc.).
102+
* */
103+
public actual open class InvalidKeyException: KeyException {
104+
public actual constructor(): super()
105+
public actual constructor(message: String?): super(message)
106+
public actual constructor(message: String?, cause: Throwable?): super(message, cause)
107+
public actual constructor(cause: Throwable?): super(cause)
108+
}
109+
110+
/**
111+
* This exception is thrown when a buffer provided by the user is too short to hold the operation result.
112+
* */
113+
public actual open class ShortBufferException: GeneralSecurityException {
114+
public actual constructor(): super()
115+
public actual constructor(message: String?): super(message)
116+
}

0 commit comments

Comments
 (0)