66import com .fasterxml .jackson .core .Base64Variants ;
77import com .fasterxml .jackson .databind .DeserializationFeature ;
88import com .fasterxml .jackson .databind .ObjectMapper ;
9+ import com .fasterxml .jackson .databind .SerializationFeature ;
910import com .fasterxml .jackson .databind .node .ObjectNode ;
1011import com .fasterxml .jackson .dataformat .cbor .CBORFactory ;
1112import com .fasterxml .jackson .datatype .jdk8 .Jdk8Module ;
@@ -28,6 +29,7 @@ public static ObjectMapper cbor() {
2829 public static ObjectMapper json () {
2930 return new ObjectMapper ()
3031 .configure (DeserializationFeature .FAIL_ON_UNKNOWN_PROPERTIES , true )
32+ .configure (SerializationFeature .FAIL_ON_EMPTY_BEANS , false )
3133 .setSerializationInclusion (Include .NON_ABSENT )
3234 .setBase64Variant (Base64Variants .MODIFIED_FOR_URL )
3335 .registerModule (new Jdk8Module ())
@@ -84,7 +86,7 @@ public static ByteArray rawEcdaKeyToCose(ByteArray key) {
8486 Map <Long , Object > coseKey = new HashMap <>();
8587
8688 coseKey .put (1L , 2L ); // Key type: EC
87- coseKey .put (3L , javaAlgorithmNameToCoseAlgorithmIdentifier ( " ES256" ) .getId ());
89+ coseKey .put (3L , COSEAlgorithmIdentifier . ES256 .getId ());
8890 coseKey .put (-1L , 1L ); // Curve: P-256
8991 coseKey .put (-2L , Arrays .copyOfRange (keyBytes , start , start + 32 )); // x
9092 coseKey .put (-3L , Arrays .copyOfRange (keyBytes , start + 32 , start + 64 )); // y
@@ -100,17 +102,4 @@ public static ECPublicKey importCoseP256PublicKey(ByteArray key) throws CoseExce
100102 return new COSE .ECPublicKey (new OneKey (CBORObject .DecodeFromBytes (key .getBytes ())));
101103 }
102104
103- public static COSEAlgorithmIdentifier javaAlgorithmNameToCoseAlgorithmIdentifier (String alg ) {
104- switch (alg ) {
105- case "ECDSA" :
106- case "ES256" :
107- return COSEAlgorithmIdentifier .ES256 ;
108-
109- case "RS256" :
110- return COSEAlgorithmIdentifier .RS256 ;
111- }
112-
113- throw new IllegalArgumentException ("Unknown algorithm: " + alg );
114- }
115-
116105}
0 commit comments