parser : implement header check

This change implements a parser method to check if the OpenPOWER VPD has
the mandatory header record, VHDR.

Change-Id: I9e4cebd8f69e47e1ab0f1b569fe4af2c82a5a137
Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
diff --git a/impl.cpp b/impl.cpp
new file mode 100644
index 0000000..74a8969
--- /dev/null
+++ b/impl.cpp
@@ -0,0 +1,55 @@
+#include <exception>
+#include <iostream>
+#include <iterator>
+#include "impl.hpp"
+
+namespace openpower
+{
+namespace vpd
+{
+namespace parser
+{
+
+namespace offsets
+{
+
+enum Offsets
+{
+    VHDR = 17
+};
+
+}
+
+namespace lengths
+{
+
+enum Lengths
+{
+    RECORD_NAME = 4,
+    RECORD_MIN = 44,
+};
+
+}
+
+void Impl::checkHeader() const
+{
+    if (vpd.empty() || (lengths::RECORD_MIN > vpd.size()))
+    {
+        throw std::runtime_error("Malformed VPD");
+    }
+    else
+    {
+        auto iterator = vpd.cbegin();
+        std::advance(iterator, offsets::VHDR);
+        auto stop = std::next(iterator, lengths::RECORD_NAME);
+        std::string record(iterator, stop);
+        if ("VHDR" != record)
+        {
+            throw std::runtime_error("VHDR record not found");
+        }
+    }
+}
+
+} // namespace parser
+} // namespace vpd
+} // namespace openpower
diff --git a/impl.hpp b/impl.hpp
index 28fcbcc..63128bf 100644
--- a/impl.hpp
+++ b/impl.hpp
@@ -54,6 +54,9 @@
         Store run();
 
     private:
+        /** @brief Checks if the VHDR record is present in the VPD */
+        void checkHeader() const;
+
         /** @brief OpenPOWER VPD in binary format */
         Binary vpd;