security: Adapt PIB to NDN Certificate Format version 2.0

The certificate format can be found at docs/specs/certificate-format.rst

Change-Id: I5656837f09ce327e06a0cb1abdf16ac28fe0b823
Refs: #3202
diff --git a/src/security/v2/certificate.cpp b/src/security/v2/certificate.cpp
index 75ee53c..b5188e9 100644
--- a/src/security/v2/certificate.cpp
+++ b/src/security/v2/certificate.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2013-2016 Regents of the University of California.
+ * Copyright (c) 2013-2017 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -132,6 +132,28 @@
           certName.get(Certificate::KEY_COMPONENT_OFFSET) == Certificate::KEY_COMPONENT);
 }
 
+Name
+extractIdentityFromCertName(const Name& certName)
+{
+  if (!Certificate::isValidName(certName)) {
+    BOOST_THROW_EXCEPTION(std::invalid_argument("Certificate name `" + certName.toUri() + "` "
+                                                "does not follow the naming conventions"));
+  }
+
+  return certName.getPrefix(Certificate::KEY_COMPONENT_OFFSET); // trim everything after and including "KEY"
+}
+
+Name
+extractKeyNameFromCertName(const Name& certName)
+{
+  if (!Certificate::isValidName(certName)) {
+    BOOST_THROW_EXCEPTION(std::invalid_argument("Certificate name `" + certName.toUri() + "` "
+                                                "does not follow the naming conventions"));
+  }
+
+  return certName.getPrefix(Certificate::KEY_ID_OFFSET + 1); // trim everything after key id
+}
+
 } // namespace v2
 } // namespace security
 } // namespace ndn