Skip to content

v1.0.0

Latest
Compare
Choose a tag to compare
@osipxd osipxd released this 17 Apr 21:11
· 25 commits to main since this release
fc9c961

Delegates to create encrypted DataStores (#24)

Delegates encryptedDataStore and encryptedPreferencesDataStore were added to simplify DataStore creation.
If you have the following code:

val dataStore = DataStoreFactory.createEncrypted(serializer) {
    EncryptedFile.Builder(
        context.dataStoreFile("filename"),
        context,
        MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC),
        EncryptedFile.FileEncryptionScheme.AES256_GCM_HKDF_4KB
    ).build()
}

You can simplify it using delegate for DataStore creation.

// 1. Move the field to top level of you Kotlin file and turn it to an extension on Context
// 2. Replace `DataStoreFactory.createEncrypted` with `encryptedDataStore`
val Context.dataStore by encryptedDataStore(
    fileName = "filename", // Keep file the same
    serializer = serializer,
)

Note

This only will be interchangeable if you used context.dataStoreFile(...) to create datastore file.
In case you have custom logic for master key creation, pass the created master key as a parameter masterKey to the delegate.

Dependencies

  • Target JVM 1.811
  • Kotlin 1.7.211.9.23
  • Tink 1.7.01.13.0

Housekeeping

  • Update Gradle to 8.7
  • Update AGP to 8.3.2
  • Move PreferenceDataStoreHack.java into encrypted-datastore-preferences module (#25)

Full Changelog: v1.0.0-beta01...v1.0.0