Skip to content

Commit

Permalink
✨ : add NoOpEncryptionService
Browse files Browse the repository at this point in the history
This way, we can always rely on a encryption service, even if it does
nothing at all.
It will allow removal of null checks un CredentialsService.
  • Loading branch information
juwit committed Aug 16, 2020
1 parent 6b4494c commit a6821f4
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/main/java/io/gaia_app/encryption/EncryptionService.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package io.gaia_app.encryption

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration

/**
* Service for encryption/decryption of data
*/
Expand All @@ -14,3 +18,24 @@ interface EncryptionService {
fun decryptBatch(cipherText: List<String>): List<String>

}

@Configuration
class NoOpEncryptionServiceConfig {

@Bean
@ConditionalOnMissingBean(EncryptionService::class)
fun noopEncryptionService() = NoOpEncryptionService()

}

class NoOpEncryptionService:EncryptionService{

override fun encrypt(plaintext: String) = plaintext

override fun encryptBatch(plaintext: List<String>) = plaintext

override fun decrypt(cipherText: String) = cipherText

override fun decryptBatch(cipherText: List<String>) = cipherText

}

0 comments on commit a6821f4

Please sign in to comment.