Skip to content

Commit 6857db0

Browse files
committed
feat(crypto): Introduce separate crypto-only module
1 parent 790a0e4 commit 6857db0

File tree

23 files changed

+215
-46
lines changed

23 files changed

+215
-46
lines changed

safebox-crypto/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

safebox-crypto/build.gradle.kts

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/*
2+
* Copyright 2025 Harry Timothy Tumalewa
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+
import com.vanniktech.maven.publish.SonatypeHost
17+
18+
plugins {
19+
id("com.android.library")
20+
id("org.jetbrains.kotlin.android")
21+
id("org.jetbrains.dokka")
22+
id("com.vanniktech.maven.publish")
23+
}
24+
25+
group = "io.github.harrytmthy"
26+
version = "1.3.0-alpha01"
27+
28+
android {
29+
namespace = "com.harrytmthy.safebox.cryptography"
30+
compileSdk = 36
31+
32+
defaultConfig {
33+
minSdk = 23
34+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
35+
consumerProguardFiles("proguard-consumer-rules.pro")
36+
}
37+
38+
buildTypes {
39+
release {
40+
isMinifyEnabled = false
41+
}
42+
}
43+
44+
compileOptions {
45+
sourceCompatibility = JavaVersion.VERSION_11
46+
targetCompatibility = JavaVersion.VERSION_11
47+
}
48+
49+
kotlinOptions {
50+
jvmTarget = "11"
51+
}
52+
}
53+
54+
dependencies {
55+
implementation(libs.androidx.annotation)
56+
implementation(libs.bouncy.castle.provider)
57+
58+
androidTestImplementation(libs.androidx.test.ext)
59+
androidTestImplementation(libs.androidx.test.runner)
60+
androidTestImplementation(libs.kotlin.test)
61+
}
62+
63+
dokka {
64+
dokkaSourceSets {
65+
configureEach {
66+
includes.from("README.md")
67+
}
68+
}
69+
}
70+
71+
tasks.register<Jar>("sourcesJar") {
72+
archiveClassifier.set("sources")
73+
from(android.sourceSets["main"].java.srcDirs)
74+
}
75+
76+
tasks.register<Jar>("javadocJar") {
77+
dependsOn("dokkaJavadoc")
78+
archiveClassifier.set("javadoc")
79+
from(tasks.named("dokkaJavadoc").map { it.outputs.files })
80+
}
81+
82+
mavenPublishing {
83+
publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL)
84+
signAllPublications()
85+
86+
pom {
87+
name.set("SafeBox Crypto")
88+
description.set("Cryptography core used by SafeBox, including ChaCha20-Poly1305 and AES-GCM keystore wrapping.")
89+
url.set("https://github.com/harrytmthy/safebox")
90+
91+
licenses {
92+
license {
93+
name.set("MIT License")
94+
url.set("https://opensource.org/licenses/MIT")
95+
}
96+
}
97+
98+
developers {
99+
developer {
100+
id.set("harrytmthy")
101+
name.set("Harry Timothy Tumalewa")
102+
email.set("harrytmthy@gmail.com")
103+
}
104+
}
105+
scm {
106+
connection.set("scm:git:git://github.com/harrytmthy/safebox.git")
107+
developerConnection.set("scm:git:ssh://github.com:harrytmthy/safebox.git")
108+
url.set("https://github.com/harrytmthy/safebox")
109+
}
110+
}
111+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright 2025 Harry Timothy Tumalewa
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy 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,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
<manifest />

safebox/src/main/java/com/harrytmthy/safebox/cryptography/AesGcmCipherProvider.kt renamed to safebox-crypto/src/main/java/com/harrytmthy/safebox/cryptography/AesGcmCipherProvider.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import android.security.keystore.KeyProperties.ENCRYPTION_PADDING_NONE
2121
import android.security.keystore.KeyProperties.KEY_ALGORITHM_AES
2222
import android.security.keystore.KeyProperties.PURPOSE_DECRYPT
2323
import android.security.keystore.KeyProperties.PURPOSE_ENCRYPT
24-
import com.harrytmthy.safebox.extensions.requireAes
2524
import com.harrytmthy.safebox.keystore.AndroidKeyStoreKeyProvider
2625
import com.harrytmthy.safebox.keystore.KeyProvider
2726
import javax.crypto.Cipher
@@ -44,7 +43,7 @@ internal class AesGcmCipherProvider private constructor(
4443

4544
override fun encrypt(plaintext: ByteArray): ByteArray {
4645
val key = keyProvider.getOrCreateKey()
47-
requireAes(key)
46+
check(key.algorithm == KEY_ALGORITHM_AES) { "Only AES keys are supported" }
4847
val cipher = Cipher.getInstance(TRANSFORMATION)
4948
cipher.init(Cipher.ENCRYPT_MODE, key)
5049
aad?.let(cipher::updateAAD)
@@ -55,7 +54,7 @@ internal class AesGcmCipherProvider private constructor(
5554

5655
override fun decrypt(ciphertext: ByteArray): ByteArray {
5756
val key = keyProvider.getOrCreateKey()
58-
requireAes(key)
57+
check(key.algorithm == KEY_ALGORITHM_AES) { "Only AES keys are supported" }
5958
val iv = ciphertext.copyOfRange(0, IV_SIZE)
6059
val actualData = ciphertext.copyOfRange(IV_SIZE, ciphertext.size)
6160
val spec = GCMParameterSpec(GCM_TAG_LENGTH_BITS, iv)
File renamed without changes.

0 commit comments

Comments
 (0)