Skip to content

Commit

Permalink
Merge pull request #7 from L-Briand/2.1.3
Browse files Browse the repository at this point in the history
2.1.3
  • Loading branch information
L-Briand authored Oct 24, 2024
2 parents dc4c578 + 1285e61 commit 41ce14f
Show file tree
Hide file tree
Showing 10 changed files with 165 additions and 45 deletions.
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

173 changes: 141 additions & 32 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ kotlin.code.style=official
kotlin.js.compiler=ir
# Global information
group=net.orandja.obor
version=2.1.2
version=2.1.3
# Artifact related
POM_NAME=OBOR
POM_DESCRIPTION=A kotlin-multiplatform library for CBOR encoding
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ For Jvm:
```kotlin
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:x.y.z")
implementation("net.orandja.obor:obor:2.1.2")
implementation("net.orandja.obor:obor:2.1.3")
}
```

Expand All @@ -25,7 +25,7 @@ kotlin {
getByName("commonMain") {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:x.y.z")
implementation("net.orandja.obor:obor:2.1.2")
implementation("net.orandja.obor:obor:2.1.3")
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/commonMain/kotlin/net/orandja/obor/data/CborBytes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ data class CborBytes(val value: ByteArray) : CborObject(Kind.BYTES) {
elements += Description(depth + 1, value, buildString {
append('"')
for (byte in value) {
val char = Char(byte.toInt())
val char = Char(byte.toUByte().toInt())
append(
if (char.isISOControl() || char.isDefined()) "\\u${char.code.toString().padStart(4, '0')}"
else char.toString()
Expand Down
14 changes: 7 additions & 7 deletions src/commonMain/kotlin/net/orandja/obor/data/CborObject.kt
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,17 @@ sealed class CborObject(val kind: Kind) {
// Utils

protected fun sizeOfMajor(value: Long) = when {
value < SIZE_8 -> 1L
value <= 0xFFL -> 2L
value <= 0xFFFFL -> 3L
value <= 0xFFFF_FFFFL -> 5L
value in 0..<SIZE_8 -> 1L
value in 0..0xFFL -> 2L
value in 0..0xFFFFL -> 3L
value in 0..0xFFFF_FFFFL -> 5L
else -> 9L
}

protected fun sizeOfMajor(value: Int) = when {
value < SIZE_8 -> 1L
value <= 0xFFL -> 2L
value <= 0xFFFFL -> 3L
value in 0..<SIZE_8 -> 1L
value in 0..0xFFL -> 2L
value in 0..0xFFFFL -> 3L
else -> 5L
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ data class CborPositive(val value: ULong) : CborObject(Kind.POSITIVE) {
withWriter: (CborWriter.() -> Unit) -> ByteArray,
) {
val cbor = withWriter { writeMajor64(MAJOR_POSITIVE, value.toLong()) }
elements += Description(depth, cbor, "unsigned($value)")
elements += Description(depth, cbor, "positive($value)")
}

internal object Serializer : KSerializer<CborPositive> {
Expand Down
2 changes: 1 addition & 1 deletion src/commonMain/kotlin/net/orandja/obor/io/CborWriter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ interface CborWriter : ByteWriter {
private val buffer: ByteArray = ByteArray(9)

override fun writeMajor8(major: Byte, value: Byte) {
if (value and SIZE_MASK < SIZE_8) write(major or value)
if (value in 0..<SIZE_8) write(major or value)
else writeHeader8(major or SIZE_8, value)
}

Expand Down
7 changes: 7 additions & 0 deletions src/commonTest/kotlin/net/orandja/obor/CborObjectTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,11 @@ class CborObjectTest {
assertContentEquals("A1636B65798B0120FA3F800000F561614101F6F7D904D2017F6161FF5F4101FF".hex(), obj.cbor)
assertEquals("A1636B65798B0120FA3F800000F561614101F6F7D904D2017F6161FF5F4101FF", obj.cborAsHexString)
}

@Test
fun complexObject() {
// https://github.com/a-sit-plus/vck/commit/de563a94ac60e6462a0ad36ea8d977d00b2ff333#diff-2622f1ec1707f34f050b29305514922d73f1db8d81094a7402156e60dd840533R74
val value = "A26A697373756572417574688443A10126A118215902E9308202E53082026AA003020102021419040C2598027AD6AC99063EE39AB8C36FA6DAE4300A06082A8648CE3D040302305C311E301C06035504030C1550494420497373756572204341202D204555203031312D302B060355040A0C24455544492057616C6C6574205265666572656E636520496D706C656D656E746174696F6E310B3009060355040613024555301E170D3233303930323137333932385A170D3234313132353137333932375A30543116301406035504030C0D504944204453202D2030303031312D302B060355040A0C24455544492057616C6C6574205265666572656E636520496D706C656D656E746174696F6E310B30090603550406130245553059301306072A8648CE3D020106082A8648CE3D0301070342000464DF85FAA25CB3830A6F83ED10FDAD6A2068540205349D71DBB0B84B2BC32E6B178E5F3F698808922EAD03B60A359AE914042CCA0513E5D51F34AB0209605F99A38201103082010C301F0603551D23041830168014418B6176E18C81DC3FB25F563FFE6CB20681E01130160603551D250101FF040C300A06082B8102020000010230430603551D1F043C303A3038A036A034863268747470733A2F2F70726570726F642E706B692E65756469772E6465762F63726C2F7069645F43415F45555F30312E63726C301D0603551D0E041604146035E1769A8317A5D92E2FFBEF492992ED0F4418300E0603551D0F0101FF040403020780305D0603551D1204563054865268747470733A2F2F6769746875622E636F6D2F65752D6469676974616C2D6964656E746974792D77616C6C65742F6172636869746563747572652D616E642D7265666572656E63652D6672616D65776F726B300A06082A8648CE3D0403020369003066023100CF75AD412DD8A9365701BB85EB844617952682D53E93181B4C66C621D99D58BED432C074040219AE599E924B7A5224EE023100903B1BDCF9AF87AD3CF63EB68119D4C0AD8FD2C9F8F9314D0A504C4E3DB5018540656132389397AFD615A43826B70A2A590259D818590254A667646F63547970657765752E6575726F70612E65632E657564692E7069642E316776657273696F6E63312E306C76616C6964697479496E666FA3667369676E6564C074323032342D31302D32335431343A32343A32355A6976616C696446726F6DC074323032342D31302D32335431343A32343A32355A6A76616C6964556E74696CC074323032352D30312D32315430303A30303A30305A6C76616C756544696765737473A17765752E6575726F70612E65632E657564692E7069642E31A8005820B7FAC61165B43D7088E504E05332E544FD05A7944865ED1D84CAFB3F8CB98CA2015820B314A01D1963184513EC7D28CE76FE4D112308D7B6059B50352AC4337E8E33D00258207580DBF64DDCB633C52C898103D546533C5F8F3FD4DB93874C219BCF51CE1912035820ABD56C84EE00E01C88C1EE9C71BEFCD1B3E22890EC0A28193BD0FC8D60662B5804582087065EA6E65356C14DCD2523F13BA27D7932C075DD345529E5621C2E80C6919405582092D5D5435000AF5BACFD16259AC88CA26F949D945B43F55986F4A921549166330658207741AD9D5E0805A378B7EE837749C61539DA9A38BF5F7222C8A380C2AAF2C8CC075820BAE6B7B63C4F107216465DF1EFE817A10F3AE9D0AF4FB827DEADD188351CF5FE6D6465766963654B6579496E666FA1696465766963654B6579A4010220012158205B6FD9E2B13EB0E5687C2668281BA2E00B74A4AD878FB89125F3489C5F6E4BED225820B5C87386D05EBFEE6FE1DA7AF3530E8E659A70154F91C594D0F953D176430F9D6F646967657374416C676F726974686D675348412D32353658404DDD44CCC2761226F02391F45A23189A7C53A5B9ADA080A23DED77A93988DC5AF59A67EC936F594AF86AE188CDC667573E377DB23657618B9FB6A24F01BF99A06A6E616D65537061636573A17765752E6575726F70612E65632E657564692E7069642E3188D818586CA46672616E646F6D5820A0A2A777A503F660A157C7B09008F606D42D353CC5A86DCB51051F02EDA1D4AA686469676573744944006C656C656D656E7456616C7565D903EC6A313936352D30312D303171656C656D656E744964656E7469666965726A62697274685F64617465D818586FA46672616E646F6D5820F41ABFAFE91CFBA92E78C249C4C92F63C60D2347B3B74D21C2A3FEFEA2DF9569686469676573744944016C656C656D656E7456616C7565D903EC6A323032342D31302D323371656C656D656E744964656E7469666965726D69737375616E63655F64617465D8185865A46672616E646F6D5820105A81F2B0F3835025EC5C8AFC1C5C55D08AC7F91BB175E858F03FE1E8BA5395686469676573744944026C656C656D656E7456616C7565666A617669657271656C656D656E744964656E7469666965726A676976656E5F6E616D65D818586DA46672616E646F6D5820C58F218133297B5413268A51F4245D06F497E189BBCD63FF5B8F04D5B75321DE686469676573744944036C656C656D656E7456616C7565D903EC6A323032352D30312D323171656C656D656E744964656E7469666965726B6578706972795F64617465D8185860A46672616E646F6D58202B27AC89B308044EA57A26CE02388C005C34E415F0E8E1F259D51999915E958B686469676573744944046C656C656D656E7456616C7565F571656C656D656E744964656E7469666965726B6167655F6F7665725F3138D8185866A46672616E646F6D582051BFD38D542495BE08327AC2064A05846836B35FBAC4F0C467DE0338072DA30B686469676573744944056C656C656D656E7456616C75656647617263696171656C656D656E744964656E7469666965726B66616D696C795F6E616D65D8185866A46672616E646F6D58203DA715C789DE91788ACD9A6A919CE82DB180C1F7D3AEB41AE81A0F0027349C29686469676573744944066C656C656D656E7456616C756562455571656C656D656E744964656E7469666965726F69737375696E675F636F756E747279D8185875A46672616E646F6D58207A17BCCBCA82615A3CB1321343CB963287482156C2C8E8563C35B8E0A3825CF0686469676573744944076C656C656D656E7456616C75656F54657374205049442069737375657271656C656D656E744964656E7469666965727169737375696E675F617574686F72697479"
assertEquals(value, Cbor.decodeFromHexString<CborObject>(value).cborAsHexString)
}
}

0 comments on commit 41ce14f

Please sign in to comment.