encoding: provide _block literal operator

_block literal operator is moved from tests and becomes public API.

refs #4722

Change-Id: I07cc040af3c4288104b66f11d91830dc9f28835a
diff --git a/src/encoding/block.cpp b/src/encoding/block.cpp
index fc9a0dc..31e6d22 100644
--- a/src/encoding/block.cpp
+++ b/src/encoding/block.cpp
@@ -25,6 +25,7 @@
 #include "buffer-stream.hpp"
 #include "encoding-buffer.hpp"
 #include "tlv.hpp"
+#include "../security/transform.hpp"
 #include "../util/string-helper.hpp"
 
 #include <boost/asio/buffer.hpp>
@@ -517,4 +518,28 @@
   return os;
 }
 
+Block
+operator "" _block(const char* input, std::size_t len)
+{
+  namespace t = security::transform;
+  t::StepSource ss;
+  OBufferStream os;
+  ss >> t::hexDecode() >> t::streamSink(os);
+
+  for (const char* end = input + len; input != end; ++input) {
+    if (std::strchr("0123456789ABCDEF", *input) != nullptr) {
+      ss.write(reinterpret_cast<const uint8_t*>(input), 1);
+    }
+  }
+
+  try {
+    ss.end();
+  }
+  catch (const t::Error&) {
+    BOOST_THROW_EXCEPTION(std::invalid_argument("input has odd number of hexadecimal digits"));
+  }
+
+  return Block(os.buf());
+}
+
 } // namespace ndn