removed unused field in ACO data

This commit is contained in:
Sergey Chernov 2022-12-02 20:09:29 +01:00
parent d12b392ed0
commit 3a65080db3

View File

@ -34,6 +34,7 @@ import kotlin.reflect.typeOf
* @param passwordKey the password-derived key that could be used to unpack the [packed] data * @param passwordKey the password-derived key that could be used to unpack the [packed] data
* @param data contains necessary data to keep and operate the ACO * @param data contains necessary data to keep and operate the ACO
*/ */
@Suppress("OPT_IN_USAGE")
class AccessControlObject<T>( class AccessControlObject<T>(
val payloadType: KType, val payloadType: KType,
val packed: ByteArray, val packed: ByteArray,
@ -62,7 +63,6 @@ class AccessControlObject<T>(
class Data<T>( class Data<T>(
val restoreId: ByteArray, val restoreId: ByteArray,
val derivedRestoreKey: SymmetricKey, val derivedRestoreKey: SymmetricKey,
val passwordKey: SymmetricKey,
val payload: T, val payload: T,
) )
@ -71,7 +71,7 @@ class AccessControlObject<T>(
* Use [packed] property on the result to save updated copy. * Use [packed] property on the result to save updated copy.
*/ */
inline fun <reified R>updatePayload(newPayload: R): AccessControlObject<R> { inline fun <reified R>updatePayload(newPayload: R): AccessControlObject<R> {
val data = Data(restoreId, data.derivedRestoreKey, passwordKey, newPayload) val data = Data(restoreId, data.derivedRestoreKey, newPayload)
return AccessControlObject<R>( return AccessControlObject<R>(
typeOf<Data<R>>(), typeOf<Data<R>>(),
Container.encrypt( Container.encrypt(
@ -87,7 +87,7 @@ class AccessControlObject<T>(
* [newPasswordKey] only. The [payload] is not changed. * [newPasswordKey] only. The [payload] is not changed.
*/ */
fun updatePasswordKey(newPasswordKey: SymmetricKey): AccessControlObject<T> { fun updatePasswordKey(newPasswordKey: SymmetricKey): AccessControlObject<T> {
val data = Data(restoreId, data.derivedRestoreKey, newPasswordKey, payload) val data = Data(restoreId, data.derivedRestoreKey, payload)
return AccessControlObject( return AccessControlObject(
payloadType, payloadType,
Container.encryptData( Container.encryptData(
@ -119,7 +119,7 @@ class AccessControlObject<T>(
): Pair<RestoreKey, ByteArray> { ): Pair<RestoreKey, ByteArray> {
val restoreKey = RestoreKey.generate() val restoreKey = RestoreKey.generate()
return restoreKey to Container.encrypt( return restoreKey to Container.encrypt(
Data(restoreKey.restoreId, restoreKey.key, passwordKey,payload), Data(restoreKey.restoreId, restoreKey.key, payload),
passwordKey, restoreKey.key passwordKey, restoreKey.key
) )
} }
@ -146,7 +146,7 @@ class AccessControlObject<T>(
*/ */
suspend inline fun <reified T> unpackWithSecret(packed: ByteArray, secret: String): AccessControlObject<T>? { suspend inline fun <reified T> unpackWithSecret(packed: ByteArray, secret: String): AccessControlObject<T>? {
try { try {
val (id, key) = RestoreKey.parse(secret) val (_, key) = RestoreKey.parse(secret)
return unpackWithKey(packed, key) return unpackWithKey(packed, key)
} }
catch(_: RestoreKey.InvalidSecretException) { catch(_: RestoreKey.InvalidSecretException) {