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" |
| 11 | #include <ndn-cpp/security/security-exception.hpp> |
| 12 | #include <ndn-cpp/security/identity/identity-storage.hpp> |
| 13 | |
| 14 | using namespace std; |
| 15 | |
| 16 | namespace ndn { |
| 17 | |
| 18 | Name |
| 19 | IdentityStorage::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 | |
| 41 | Name |
| 42 | IdentityStorage::getDefaultCertificateNameForIdentity (const Name& identityName) |
| 43 | { |
| 44 | Name keyName = getDefaultKeyNameForIdentity(identityName); |
| 45 | return getDefaultCertificateNameForKey(keyName); |
| 46 | } |
| 47 | |
| 48 | } |