blob: 685933270e6dc98eb80fd1d1af03245af20087b3 [file] [log] [blame]
Jeff Thompson22285ec2013-10-22 17:43:02 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/**
3 * Copyright (C) 2013 Regents of the University of California.
4 * @author: Yingdi Yu <yingdi@cs.ucla.edu>
5 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
6 * See COPYING for copyright and distribution information.
7 */
8
9#include <math.h>
10#include "../../c/util/time.h"
11#include <ndn-cpp/security/security-exception.hpp>
12#include <ndn-cpp/security/identity/identity-storage.hpp>
13
14using namespace std;
15
16namespace ndn {
17
18Name
19IdentityStorage::getNewKeyName (const Name& identityName, bool useKsk)
20{
21 MillisecondsSince1970 ti = ::ndn_getNowMilliseconds();
22 // Get the number of seconds.
23 ostringstream oss;
24 oss << floor(ti / 1000.0);
25
26 string keyIdStr;
27
28 if (useKsk)
29 keyIdStr = ("KSK-" + oss.str());
30 else
31 keyIdStr = ("DSK-" + oss.str());
32
33 Name keyName = Name(identityName).append(keyIdStr);
34
35 if (doesKeyExist(keyName))
36 throw SecurityException("Key name already exists");
37
38 return keyName;
39}
40
41Name
42IdentityStorage::getDefaultCertificateNameForIdentity (const Name& identityName)
43{
44 Name keyName = getDefaultKeyNameForIdentity(identityName);
45 return getDefaultCertificateNameForKey(keyName);
46}
47
48}