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

craterdog.notary.mappers.NotaryModule Maven / Gradle / Ivy

/************************************************************************
 * Copyright (c) Crater Dog Technologies(TM).  All Rights Reserved.     *
 ************************************************************************
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.        *
 *                                                                      *
 * This code is free software; you can redistribute it and/or modify it *
 * under the terms of The MIT License (MIT), as published by the Open   *
 * Source Initiative. (See http://opensource.org/licenses/MIT)          *
 ************************************************************************/
package craterdog.notary.mappers;

import com.fasterxml.jackson.databind.module.SimpleModule;
import java.security.PrivateKey;
import java.security.PublicKey;

/**
 * This class is a Jackson module that can be added to an object mapper to handle the serialization
 * of a notary keys.  The private signing key is password protected.
 *
 * @author Derk Norton
 */
public class NotaryModule extends SimpleModule {

    /**
     * This default constructor adds serializers and deserializers for the public and private keys
     * that make up a notary key.  The serializers will not serialize or deserialize the private
     * key.
     */
    public NotaryModule() {
        super("NotaryModule");
        addSerializer(PublicKey.class, new PublicKeySerializer());
        addDeserializer(PublicKey.class, new PublicKeyDeserializer());
        addSerializer(PrivateKey.class, new PrivateKeySerializer());
        addDeserializer(PrivateKey.class, new PrivateKeyDeserializer());
    }


    /**
     * This constructor adds serializers and deserializers for the public and private keys
     * that make up a notary key.
     * @param password The password to be used to encrypt the private key.
     */
    public NotaryModule(char[] password) {
        super("NotaryModule");
        addSerializer(PublicKey.class, new PublicKeySerializer());
        addDeserializer(PublicKey.class, new PublicKeyDeserializer());
        addSerializer(PrivateKey.class, new PrivateKeySerializer(password));
        addDeserializer(PrivateKey.class, new PrivateKeyDeserializer(password));
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy