blob: d16d742d374285f36609117787c92d7c676e36f7 [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"
Jeff Thompson22285ec2013-10-22 17:43:02 -070011#include <ndn-cpp/security/identity/identity-storage.hpp>
12
13using namespace std;
14
15namespace ndn {
16
17Name
18IdentityStorage::getNewKeyName (const Name& identityName, bool useKsk)
19{
20 MillisecondsSince1970 ti = ::ndn_getNowMilliseconds();
21 // Get the number of seconds.
22 ostringstream oss;
23 oss << floor(ti / 1000.0);
24
25 string keyIdStr;
26
27 if (useKsk)
28 keyIdStr = ("KSK-" + oss.str());
29 else
30 keyIdStr = ("DSK-" + oss.str());
31
32 Name keyName = Name(identityName).append(keyIdStr);
33
34 if (doesKeyExist(keyName))
Alexander Afanasyevfab95ed2014-01-05 23:26:30 -080035 throw Error("Key name already exists");
Jeff Thompson22285ec2013-10-22 17:43:02 -070036
37 return keyName;
38}
39
40Name
41IdentityStorage::getDefaultCertificateNameForIdentity (const Name& identityName)
42{
43 Name keyName = getDefaultKeyNameForIdentity(identityName);
44 return getDefaultCertificateNameForKey(keyName);
45}
46
47}