All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dev.fitko.fitconnect.api.domain.model.reply.replychannel.EncryptionPublicKey Maven / Gradle / Ivy

Go to download

Library that provides client access to the FIT-Connect api-endpoints for sending, subscribing and routing

There is a newer version: 2.3.5
Show newest version
package dev.fitko.fitconnect.api.domain.model.reply.replychannel;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.nimbusds.jose.jwk.JWK;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import static com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class EncryptionPublicKey {

    private static final ObjectMapper MAPPER = new ObjectMapper().configure(FAIL_ON_UNKNOWN_PROPERTIES, false);

    @JsonProperty("kty")
    private String kty;

    @JsonProperty("key_ops")
    private List keyOps = new ArrayList<>();

    @JsonProperty("alg")
    private String alg;

    @JsonProperty("kid")
    private String kid;

    @JsonProperty("n")
    private String n;

    @JsonProperty("e")
    private String e;

    public static EncryptionPublicKey fromJwk(final JWK jwk) {
        final Map jsonObject = jwk.toJSONObject();
        try {
            return MAPPER.readValue(MAPPER.writeValueAsString(jsonObject), EncryptionPublicKey.class);
        } catch (final JsonProcessingException ex) {
            throw new RuntimeException(ex);
        }
    }

    public JWK toJwk() {
        try {
            return JWK.parse(MAPPER.writeValueAsString(this));
        } catch (final JsonProcessingException | ParseException ex) {
            throw new RuntimeException(ex);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy