-
Notifications
You must be signed in to change notification settings - Fork 614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CBOR Feature Drop: COSE #2412
Open
JesusMcCloud
wants to merge
43
commits into
Kotlin:dev
Choose a base branch
from
a-sit-plus:feature/coseUpstream
base: dev
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
CBOR Feature Drop: COSE #2412
Changes from 30 commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
c2db1cf
CBOR basic value tagging
JesusMcCloud 1edcec3
CBOR: handle tagged keys
JesusMcCloud 04826be
CBOR: make verifying and writing tags optional
JesusMcCloud 8979a6e
CBOR: fix decoding value tags, add tests
JesusMcCloud 3e235dd
CBOR: refactor Tagged → ValueTags
JesusMcCloud 256e12d
CBOR: Fixes (docs, whitespace, names, superflous params)
JesusMcCloud eaf5ef1
CBOR: serialize cbor to tree
JesusMcCloud d68c3a3
CBOR: tree fixes
JesusMcCloud db1700b
CBOR: frankensteined data tree
JesusMcCloud 45f70e9
CBOR: fix direct encoding of primitives
JesusMcCloud 79bf170
CBOR: write definite lengths
JesusMcCloud b0b9974
CBOR: experiment with pruning null properties
JesusMcCloud 19f9227
CBOR: Catch errors on finding annotations
nodh b2cc8bc
CBOR: Implement labels to use as map keys
nodh c78f102
WIP: Ignore failing tests
nodh 2e84646
CBOR: Add option to write serial labels over names
nodh b4e3942
CBOR: Add annotation @CborArray to encode classes as arrays
nodh a9d00c2
CBOR: Add convenience class for wrapping byte strings during serializ…
nodh 2ef81c4
CBOR: Test combination of serial label with tags
nodh 51bb184
CBOR: Add option to always use compact byte string encoding
nodh 2c558f0
CBOR: Fix potential issue with custom serializers
nodh 1c6edde
CBOR: Encode null complex object as empty map
nodh 337555e
CBOR: remove recursion and null pruning
JesusMcCloud 0d351c1
CBOR: remove bogus `explicitNulls`
JesusMcCloud dbebe10
CBOR: streamline an simplify encoding
JesusMcCloud ad25978
CBOR: minor cleanups
JesusMcCloud 0e5e519
CBOR: fix polymorphism
JesusMcCloud 36655cb
CBOR: document new features
JesusMcCloud f160d70
CBOR: run knit+ fix docs
JesusMcCloud 751aa81
CBOR: update API dumps
JesusMcCloud da25674
CBOR: Provide serializer for ByteStringWrapper
nodh 68218a1
CBOR: Rename "SerialLabel" to "CborLabel"
nodh 2c4ff1e
CBOR: Add documentation to CborLabel and CborArray
nodh d4e2052
CBOR: Suppress warning about desugared API on Android
nodh d3039fb
CBOR: remove Encoder class
JesusMcCloud f8d7dfd
Merge 'upstream/dev' into feature/coseUpstream
JesusMcCloud 91e97c9
CBOR: don't preallocate for preamble
JesusMcCloud 4786990
CBOR: don't preallocate for data
JesusMcCloud b415365
CBOR: minor adjustments (missing docs, formatting, …)
JesusMcCloud dbb9d0e
CBOR: simplify encoding and comment data structures
JesusMcCloud 77e89c7
CBOR: minor cleanups
JesusMcCloud 4f8b680
run knit
JesusMcCloud 1137c42
update API dump
JesusMcCloud File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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
67 changes: 67 additions & 0 deletions
67
formats/cbor/commonMain/src/kotlinx/serialization/cbor/ByteStringWrapper.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,67 @@ | ||
package kotlinx.serialization.cbor | ||
|
||
/** | ||
* Use this class if you'll need to serialize a complex type as a byte string before encoding it, | ||
* i.e. as it is the case with the protected header in COSE structures. | ||
* | ||
* Clients also need to write a custom serializer, i.e. in the form of | ||
* | ||
* ``` | ||
* @Serializable | ||
* data class CoseHeader( | ||
* @SerialLabel(1) | ||
* @SerialName("alg") | ||
* val alg: Int? = null | ||
* ) | ||
* | ||
* @Serializable | ||
* data class CoseSigned( | ||
* @Serializable(with = ByteStringWrapperSerializer::class) | ||
* @ByteString | ||
* @SerialLabel(1) | ||
* @SerialName("protectedHeader") | ||
* val protectedHeader: ByteStringWrapper<CoseHeader>, | ||
sandwwraith marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* ) | ||
* | ||
* object ByteStringWrapperSerializer : KSerializer<ByteStringWrapper<CoseHeader>> { | ||
* override val descriptor: SerialDescriptor = | ||
* PrimitiveSerialDescriptor("ByteStringWrapperSerializer", PrimitiveKind.STRING) | ||
* override fun serialize(encoder: Encoder, value: ByteStringWrapper<CoseHeader>) { | ||
* val bytes = Cbor.encodeToByteArray(value.value) | ||
* encoder.encodeSerializableValue(ByteArraySerializer(), bytes) | ||
* } | ||
* override fun deserialize(decoder: Decoder): ByteStringWrapper<CoseHeader> { | ||
* val bytes = decoder.decodeSerializableValue(ByteArraySerializer()) | ||
* return ByteStringWrapper(Cbor.decodeFromByteArray(bytes), bytes) | ||
* } | ||
* } | ||
* ``` | ||
* | ||
* then serializing a `CoseSigned` object would result in `a10143a10126`, in diagnostic notation: | ||
* | ||
* ``` | ||
* A1 # map(1) | ||
* 01 # unsigned(1) | ||
* 43 # bytes(3) | ||
* A10126 # "\xA1\u0001&" | ||
* ``` | ||
* | ||
* so the `protectedHeader` got serialized first and then encoded as a `@ByteString` | ||
*/ | ||
public data class ByteStringWrapper<T>( | ||
val value: T, | ||
val serialized: ByteArray = byteArrayOf() | ||
) { | ||
override fun equals(other: Any?): Boolean { | ||
sandwwraith marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (this === other) return true | ||
if (other == null || this::class != other::class) return false | ||
|
||
other as ByteStringWrapper<*> | ||
|
||
return value == other.value | ||
} | ||
|
||
override fun hashCode(): Int { | ||
return value?.hashCode() ?: 0 | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe
ValueTags.Companion
should be mentioned here as a source for pre-defined tagsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done