Skip to content

Add security exception classes #107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions library/core/api/core.klib.api
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,65 @@ abstract interface org.kotlincrypto.core/Updatable { // org.kotlincrypto.core/Up
abstract fun update(kotlin/ByteArray) // org.kotlincrypto.core/Updatable.update|update(kotlin.ByteArray){}[0]
abstract fun update(kotlin/ByteArray, kotlin/Int, kotlin/Int) // org.kotlincrypto.core/Updatable.update|update(kotlin.ByteArray;kotlin.Int;kotlin.Int){}[0]
}

open class org.kotlincrypto.core/BadPaddingException : org.kotlincrypto.core/GeneralSecurityException { // org.kotlincrypto.core/BadPaddingException|null[0]
constructor <init>() // org.kotlincrypto.core/BadPaddingException.<init>|<init>(){}[0]
constructor <init>(kotlin/String?) // org.kotlincrypto.core/BadPaddingException.<init>|<init>(kotlin.String?){}[0]
}

open class org.kotlincrypto.core/CertificateEncodingException : org.kotlincrypto.core/CertificateException { // org.kotlincrypto.core/CertificateEncodingException|null[0]
constructor <init>() // org.kotlincrypto.core/CertificateEncodingException.<init>|<init>(){}[0]
constructor <init>(kotlin/String?) // org.kotlincrypto.core/CertificateEncodingException.<init>|<init>(kotlin.String?){}[0]
constructor <init>(kotlin/String?, kotlin/Throwable?) // org.kotlincrypto.core/CertificateEncodingException.<init>|<init>(kotlin.String?;kotlin.Throwable?){}[0]
constructor <init>(kotlin/Throwable?) // org.kotlincrypto.core/CertificateEncodingException.<init>|<init>(kotlin.Throwable?){}[0]
}

open class org.kotlincrypto.core/CertificateException : org.kotlincrypto.core/GeneralSecurityException { // org.kotlincrypto.core/CertificateException|null[0]
constructor <init>() // org.kotlincrypto.core/CertificateException.<init>|<init>(){}[0]
constructor <init>(kotlin/String?) // org.kotlincrypto.core/CertificateException.<init>|<init>(kotlin.String?){}[0]
constructor <init>(kotlin/String?, kotlin/Throwable?) // org.kotlincrypto.core/CertificateException.<init>|<init>(kotlin.String?;kotlin.Throwable?){}[0]
constructor <init>(kotlin/Throwable?) // org.kotlincrypto.core/CertificateException.<init>|<init>(kotlin.Throwable?){}[0]
}

open class org.kotlincrypto.core/CertificateParsingException : org.kotlincrypto.core/CertificateException { // org.kotlincrypto.core/CertificateParsingException|null[0]
constructor <init>() // org.kotlincrypto.core/CertificateParsingException.<init>|<init>(){}[0]
constructor <init>(kotlin/String?) // org.kotlincrypto.core/CertificateParsingException.<init>|<init>(kotlin.String?){}[0]
constructor <init>(kotlin/String?, kotlin/Throwable?) // org.kotlincrypto.core/CertificateParsingException.<init>|<init>(kotlin.String?;kotlin.Throwable?){}[0]
constructor <init>(kotlin/Throwable?) // org.kotlincrypto.core/CertificateParsingException.<init>|<init>(kotlin.Throwable?){}[0]
}

open class org.kotlincrypto.core/GeneralSecurityException : kotlin/Exception { // org.kotlincrypto.core/GeneralSecurityException|null[0]
constructor <init>() // org.kotlincrypto.core/GeneralSecurityException.<init>|<init>(){}[0]
constructor <init>(kotlin/String?) // org.kotlincrypto.core/GeneralSecurityException.<init>|<init>(kotlin.String?){}[0]
constructor <init>(kotlin/String?, kotlin/Throwable?) // org.kotlincrypto.core/GeneralSecurityException.<init>|<init>(kotlin.String?;kotlin.Throwable?){}[0]
constructor <init>(kotlin/Throwable?) // org.kotlincrypto.core/GeneralSecurityException.<init>|<init>(kotlin.Throwable?){}[0]
}

open class org.kotlincrypto.core/IllegalBlockSizeException : org.kotlincrypto.core/GeneralSecurityException { // org.kotlincrypto.core/IllegalBlockSizeException|null[0]
constructor <init>() // org.kotlincrypto.core/IllegalBlockSizeException.<init>|<init>(){}[0]
constructor <init>(kotlin/String?) // org.kotlincrypto.core/IllegalBlockSizeException.<init>|<init>(kotlin.String?){}[0]
}

open class org.kotlincrypto.core/InvalidKeyException : org.kotlincrypto.core/KeyException { // org.kotlincrypto.core/InvalidKeyException|null[0]
constructor <init>() // org.kotlincrypto.core/InvalidKeyException.<init>|<init>(){}[0]
constructor <init>(kotlin/String?) // org.kotlincrypto.core/InvalidKeyException.<init>|<init>(kotlin.String?){}[0]
constructor <init>(kotlin/String?, kotlin/Throwable?) // org.kotlincrypto.core/InvalidKeyException.<init>|<init>(kotlin.String?;kotlin.Throwable?){}[0]
constructor <init>(kotlin/Throwable?) // org.kotlincrypto.core/InvalidKeyException.<init>|<init>(kotlin.Throwable?){}[0]
}

open class org.kotlincrypto.core/InvalidParameterException : kotlin/IllegalArgumentException { // org.kotlincrypto.core/InvalidParameterException|null[0]
constructor <init>() // org.kotlincrypto.core/InvalidParameterException.<init>|<init>(){}[0]
constructor <init>(kotlin/String?) // org.kotlincrypto.core/InvalidParameterException.<init>|<init>(kotlin.String?){}[0]
}

open class org.kotlincrypto.core/KeyException : org.kotlincrypto.core/GeneralSecurityException { // org.kotlincrypto.core/KeyException|null[0]
constructor <init>() // org.kotlincrypto.core/KeyException.<init>|<init>(){}[0]
constructor <init>(kotlin/String?) // org.kotlincrypto.core/KeyException.<init>|<init>(kotlin.String?){}[0]
constructor <init>(kotlin/String?, kotlin/Throwable?) // org.kotlincrypto.core/KeyException.<init>|<init>(kotlin.String?;kotlin.Throwable?){}[0]
constructor <init>(kotlin/Throwable?) // org.kotlincrypto.core/KeyException.<init>|<init>(kotlin.Throwable?){}[0]
}

open class org.kotlincrypto.core/ShortBufferException : org.kotlincrypto.core/GeneralSecurityException { // org.kotlincrypto.core/ShortBufferException|null[0]
constructor <init>() // org.kotlincrypto.core/ShortBufferException.<init>|<init>(){}[0]
constructor <init>(kotlin/String?) // org.kotlincrypto.core/ShortBufferException.<init>|<init>(kotlin.String?){}[0]
}
116 changes: 116 additions & 0 deletions library/core/src/commonMain/kotlin/org/kotlincrypto/core/Exceptions.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
* Copyright (c) 2025 Matthew Nelson
*
* 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
*
* https://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.
**/
@file:Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING")

package org.kotlincrypto.core

/**
* This exception is thrown when an invalid parameter is encountered.
* */
public expect open class InvalidParameterException: IllegalArgumentException {
public constructor()
public constructor(message: String?)
}

/**
* The `GeneralSecurityException` class is a generic security exception class that provides type
* safety for all the security-related exception classes that extend from it.
* */
public expect open class GeneralSecurityException: Exception {
public constructor()
public constructor(message: String?)
public constructor(message: String?, cause: Throwable?)
public constructor(cause: Throwable?)
}

/**
* This exception is thrown when a particular padding mechanism is expected for the input data but
* the data is not padded properly.
* */
public expect open class BadPaddingException: GeneralSecurityException {
public constructor()
public constructor(message: String?)
}

/**
* The `CertificateException` class is a generic security exception class that provides type safety
* for all the certificate-related exception classes that extend from it.
* */
public expect open class CertificateException: GeneralSecurityException {
public constructor()
public constructor(message: String?)
public constructor(message: String?, cause: Throwable?)
public constructor(cause: Throwable?)
}

/**
* This exception is thrown when an error occurs while attempting to encode a certificate.
* */
public expect open class CertificateEncodingException: CertificateException {
public constructor()
public constructor(message: String?)
public constructor(message: String?, cause: Throwable?)
public constructor(cause: Throwable?)
}

/**
* This exception is thrown whenever an invalid DER-encoded certificate is parsed, or unsupported
* DER features are found in the Certificate.
* */
public expect open class CertificateParsingException: CertificateException {
public constructor()
public constructor(message: String?)
public constructor(message: String?, cause: Throwable?)
public constructor(cause: Throwable?)
}

/**
* This exception is thrown when the length of data provided to a block cipher is incorrect, (i.e.
* does not match the block size of the cipher.)
* */
public expect open class IllegalBlockSizeException: GeneralSecurityException {
public constructor()
public constructor(message: String?)
}

/**
* The `KeyException` class is a generic security exception class that provides type safety for all
* the key-related exception classes that extend from it.
* */
public expect open class KeyException: GeneralSecurityException {
public constructor()
public constructor(message: String?)
public constructor(message: String?, cause: Throwable?)
public constructor(cause: Throwable?)
}

/**
* This exception is thrown when a key is invalid (e.g. invalid encoding, wrong length, etc.).
* */
public expect open class InvalidKeyException: KeyException {
public constructor()
public constructor(message: String?)
public constructor(message: String?, cause: Throwable?)
public constructor(cause: Throwable?)
}

/**
* This exception is thrown when a buffer provided by the user is too short to hold the operation result.
* */
public expect open class ShortBufferException: GeneralSecurityException {
public constructor()
public constructor(message: String?)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2025 Matthew Nelson
*
* 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
*
* https://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.
**/
@file:Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING")

package org.kotlincrypto.core

public actual typealias InvalidParameterException = java.security.InvalidParameterException
public actual typealias GeneralSecurityException = java.security.GeneralSecurityException
public actual typealias BadPaddingException = javax.crypto.BadPaddingException
public actual typealias CertificateException = java.security.cert.CertificateException
public actual typealias CertificateEncodingException = java.security.cert.CertificateEncodingException
public actual typealias CertificateParsingException = java.security.cert.CertificateParsingException
public actual typealias IllegalBlockSizeException = javax.crypto.IllegalBlockSizeException
public actual typealias KeyException = java.security.KeyException
public actual typealias InvalidKeyException = java.security.InvalidKeyException
public actual typealias ShortBufferException = javax.crypto.ShortBufferException
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
* Copyright (c) 2025 Matthew Nelson
*
* 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
*
* https://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.
**/
@file:Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING")

package org.kotlincrypto.core

/**
* This exception is thrown when an invalid parameter is encountered.
* */
public actual open class InvalidParameterException: IllegalArgumentException {
public actual constructor(): super()
public actual constructor(message: String?): super(message)
}

/**
* The `GeneralSecurityException` class is a generic security exception class that provides type
* safety for all the security-related exception classes that extend from it.
* */
public actual open class GeneralSecurityException: Exception {
public actual constructor(): super()
public actual constructor(message: String?): super(message)
public actual constructor(message: String?, cause: Throwable?): super(message, cause)
public actual constructor(cause: Throwable?): super(cause)
}

/**
* This exception is thrown when a particular padding mechanism is expected for the input data but
* the data is not padded properly.
* */
public actual open class BadPaddingException: GeneralSecurityException {
public actual constructor(): super()
public actual constructor(message: String?): super(message)
}

/**
* The `CertificateException` class is a generic security exception class that provides type safety
* for all the certificate-related exception classes that extend from it.
* */
public actual open class CertificateException: GeneralSecurityException {
public actual constructor(): super()
public actual constructor(message: String?): super(message)
public actual constructor(message: String?, cause: Throwable?): super(message, cause)
public actual constructor(cause: Throwable?): super(cause)
}

/**
* This exception is thrown when an error occurs while attempting to encode a certificate.
* */
public actual open class CertificateEncodingException: CertificateException {
public actual constructor(): super()
public actual constructor(message: String?): super(message)
public actual constructor(message: String?, cause: Throwable?): super(message, cause)
public actual constructor(cause: Throwable?): super(cause)
}

/**
* This exception is thrown whenever an invalid DER-encoded certificate is parsed, or unsupported
* DER features are found in the Certificate.
* */
public actual open class CertificateParsingException: CertificateException {
public actual constructor(): super()
public actual constructor(message: String?): super(message)
public actual constructor(message: String?, cause: Throwable?): super(message, cause)
public actual constructor(cause: Throwable?): super(cause)
}

/**
* This exception is thrown when the length of data provided to a block cipher is incorrect, (i.e.
* does not match the block size of the cipher.)
* */
public actual open class IllegalBlockSizeException: GeneralSecurityException {
public actual constructor(): super()
public actual constructor(message: String?): super(message)
}

/**
* The `KeyException` class is a generic security exception class that provides type safety for all
* the key-related exception classes that extend from it.
* */
public actual open class KeyException: GeneralSecurityException {
public actual constructor(): super()
public actual constructor(message: String?): super(message)
public actual constructor(message: String?, cause: Throwable?): super(message, cause)
public actual constructor(cause: Throwable?): super(cause)
}

/**
* This exception is thrown when a key is invalid (e.g. invalid encoding, wrong length, etc.).
* */
public actual open class InvalidKeyException: KeyException {
public actual constructor(): super()
public actual constructor(message: String?): super(message)
public actual constructor(message: String?, cause: Throwable?): super(message, cause)
public actual constructor(cause: Throwable?): super(cause)
}

/**
* This exception is thrown when a buffer provided by the user is too short to hold the operation result.
* */
public actual open class ShortBufferException: GeneralSecurityException {
public actual constructor(): super()
public actual constructor(message: String?): super(message)
}
Loading