/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
/**
 * Copyright (C) 2013 Regents of the University of California.
 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
 * See COPYING for copyright and distribution information.
 */

#ifndef NDN_SIGNATURE_HPP
#define NDN_SIGNATURE_HPP

namespace ndn {

/**
 * A Signature is storage for the signature-related information (info and value) in a Data packet.
 */
class Signature {
public:
  struct Error : public std::runtime_error { Error(const std::string &what) : std::runtime_error(what) {} };

  enum {
    Sha256 = 0,
    Sha256WithRsa = 1
  };
  
  Signature()
    : type_(-1)
  {
  }
  
  Signature(const Block &info, const Block &value)
    : value_(value)
  {
    setInfo(info);
  }

  operator bool() const
  {
    return type_ != -1;
  }

  uint32_t
  getType() const
  {
    return type_;
  }
  
  const Block&
  getInfo() const
  {
    info_.encode(); // will do nothing if wire already exists
    return info_;
  }

  void
  setInfo(const Block &info)
  {
    info_ = info;
    if (info_.hasWire() || info_.hasValue())
      {
        info_.parse();
        const Block &signatureType = info_.get(Tlv::SignatureType);
        type_ = readNonNegativeInteger(signatureType);
      }
    else
      {
        type_ = -1;
      }
  }  

  const Block&
  getValue() const
  {
    value_.encode(); // will do nothing if wire already exists
    return value_;
  }

  void
  setValue(const Block &value)
  {
    value_ = value;
  }

  void
  reset()
  {
    type_ = -1;
    info_.reset();
    value_.reset();
  }

protected:
  int32_t type_;
  
  mutable Block info_;
  mutable Block value_;
};

} // namespace ndn

#endif // NDN_SIGNATURE_HPP
