Jeff Thompson | 22285ec | 2013-10-22 17:43:02 -0700 | [diff] [blame] | 1 | /* -*- 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 Thompson | 22285ec | 2013-10-22 17:43:02 -0700 | [diff] [blame] | 11 | #include <ndn-cpp/security/identity/identity-storage.hpp> |
| 12 | |
| 13 | using namespace std; |
| 14 | |
| 15 | namespace ndn { |
| 16 | |
| 17 | Name |
| 18 | IdentityStorage::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 Afanasyev | fab95ed | 2014-01-05 23:26:30 -0800 | [diff] [blame^] | 35 | throw Error("Key name already exists"); |
Jeff Thompson | 22285ec | 2013-10-22 17:43:02 -0700 | [diff] [blame] | 36 | |
| 37 | return keyName; |
| 38 | } |
| 39 | |
| 40 | Name |
| 41 | IdentityStorage::getDefaultCertificateNameForIdentity (const Name& identityName) |
| 42 | { |
| 43 | Name keyName = getDefaultKeyNameForIdentity(identityName); |
| 44 | return getDefaultCertificateNameForKey(keyName); |
| 45 | } |
| 46 | |
| 47 | } |