/**
 * @author: Jeff Thompson
 * See COPYING for copyright and distribution information.
 */

#include "sha256-with-rsa-signature.hpp"

using namespace std;

namespace ndn {

ptr_lib::shared_ptr<Signature> Sha256WithRsaSignature::clone() const
{
  return ptr_lib::shared_ptr<Signature>(new Sha256WithRsaSignature(*this));
}

void Sha256WithRsaSignature::get(struct ndn_Signature& signatureStruct) const 
{
  signatureStruct.digestAlgorithmLength = digestAlgorithm_.size();
  if (digestAlgorithm_.size() > 0)
    signatureStruct.digestAlgorithm = (unsigned char *)digestAlgorithm_.buf();
  else
    signatureStruct.digestAlgorithm = 0;

  signatureStruct.witnessLength = witness_.size();
  if (witness_.size() > 0)
    signatureStruct.witness = (unsigned char *)witness_.buf();
  else
    signatureStruct.witness = 0;

  signatureStruct.signatureLength = signature_.size();
  if (signature_.size() > 0)
    signatureStruct.signature = (unsigned char *)signature_.buf();
  else
    signatureStruct.signature = 0;
  
  publisherPublicKeyDigest_.get(signatureStruct.publisherPublicKeyDigest);
  keyLocator_.get(signatureStruct.keyLocator);
}

void Sha256WithRsaSignature::set(const struct ndn_Signature& signatureStruct)
{
  digestAlgorithm_ = Blob(signatureStruct.digestAlgorithm, signatureStruct.digestAlgorithmLength);
  witness_ = Blob(signatureStruct.witness, signatureStruct.witnessLength);
  signature_ = Blob(signatureStruct.signature, signatureStruct.signatureLength);
  publisherPublicKeyDigest_.set(signatureStruct.publisherPublicKeyDigest);
  keyLocator_.set(signatureStruct.keyLocator);
}

}
