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

#include "common.hpp"
#include "key.hpp"

using namespace std;

namespace ndn {

void KeyLocator::get(struct ndn_KeyLocator& keyLocatorStruct) const 
{
  keyLocatorStruct.type = type_;
  
  keyLocatorStruct.keyDataLength = keyData_.size();
  if (keyData_.size() > 0)
    keyLocatorStruct.keyData = (unsigned char *)keyData_.buf();
  else
    keyLocatorStruct.keyData = 0;

  keyName_.get(keyLocatorStruct.keyName);
  keyLocatorStruct.keyNameType = keyNameType_;
}

void KeyLocator::set(const struct ndn_KeyLocator& keyLocatorStruct)
{
  type_ = keyLocatorStruct.type;
  keyData_ = Blob(keyLocatorStruct.keyData, keyLocatorStruct.keyDataLength);
  if (keyLocatorStruct.type == ndn_KeyLocatorType_KEYNAME) {
    keyName_.set(keyLocatorStruct.keyName);
    keyNameType_ = keyLocatorStruct.keyNameType;
  }
  else {
    keyName_.clear();
    keyNameType_ = (ndn_KeyNameType)-1;
  }
}

}

