-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract new interfaces, classes for chains into separate files
- Loading branch information
Showing
5 changed files
with
89 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/commonMain/kotlin/ehn/techiop/hcert/kotlin/chain/DelegatingChain.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package ehn.techiop.hcert.kotlin.chain | ||
|
||
import ehn.techiop.hcert.kotlin.data.GreenCertificate | ||
|
||
/** | ||
* Can decode incoming HCERT data depending on Context, e.g. either "HC1:" or "AT1:" | ||
*/ | ||
class DelegatingChain( | ||
private val euChain: Chain, | ||
private val euContextService: ContextIdentifierService, | ||
private val atChain: Chain, | ||
private val atContextService: ContextIdentifierService | ||
) : IChain { | ||
|
||
override fun encode(input: GreenCertificate): ChainResult { | ||
return euChain.encode(input) | ||
} | ||
|
||
override fun decode(input: String): DecodeResult { | ||
val check = VerificationResult() | ||
return try { | ||
euContextService.decode(input, check) | ||
euChain.decode(input) | ||
} catch (_: VerificationException) { | ||
try { | ||
atContextService.decode(input, check) | ||
atChain.decode(input) | ||
} catch (e: VerificationException) { | ||
DecodeResult( | ||
VerificationResult().apply { error = e.error;e.details?.let { errorDetails.putAll(it) } }, | ||
ChainDecodeResult(listOf(e.error), null, null, null, null, null, null) | ||
) | ||
} | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/commonMain/kotlin/ehn/techiop/hcert/kotlin/chain/IChain.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package ehn.techiop.hcert.kotlin.chain | ||
|
||
import ehn.techiop.hcert.kotlin.data.GreenCertificate | ||
import kotlin.js.JsName | ||
|
||
/** | ||
* Interface for the encoding / decoding chain | ||
*/ | ||
interface IChain { | ||
/** | ||
* Process the [input], apply encoding in this order: | ||
* - [CborService] | ||
* - [CwtService] | ||
* - [CoseService] | ||
* - [CompressorService] | ||
* - [Base45Service] | ||
* - [ContextIdentifierService] | ||
* | ||
* The result ([ChainResult]) will contain all intermediate steps, as well as the final result in [ChainResult.step5Prefixed]. | ||
*/ | ||
@JsName("encode") | ||
fun encode(input: GreenCertificate): ChainResult | ||
|
||
/** | ||
* Process the [input], apply decoding in this order: | ||
* - [ContextIdentifierService] | ||
* - [Base45Service] | ||
* - [CompressorService] | ||
* - [CoseService] | ||
* - [CwtService] | ||
* - [CborService] | ||
* - [SchemaValidationService] | ||
* The result ([ChainDecodeResult]) will contain the parsed data, as well as intermediate results. | ||
*/ | ||
@JsName("decode") | ||
fun decode(input: String): DecodeResult | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters