blob: fcebfba878623db616d56ee7fe0f0a9a71a89330 [file] [log] [blame]
Jeff Thompsona8d7b062013-08-08 15:56:35 -07001/**
Jeff Thompson7687dc02013-09-13 11:54:07 -07002 * Copyright (C) 2013 Regents of the University of California.
3 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
Jeff Thompsona8d7b062013-08-08 15:56:35 -07004 * See COPYING for copyright and distribution information.
5 */
6
7#include <sstream>
8#include "common.hpp"
9
10using namespace std;
11
12namespace ndn {
13
Jeff Thompson0050abe2013-09-17 12:50:25 -070014string
Jeff Thompson10ad12a2013-09-24 16:19:11 -070015toHex(const vector<uint8_t>& array)
Jeff Thompsona8d7b062013-08-08 15:56:35 -070016{
Jeff Thompsonb0948a52013-09-12 14:38:26 -070017 if (!&array)
18 return "";
19
Jeff Thompsona8d7b062013-08-08 15:56:35 -070020 ostringstream result;
21 result.flags(ios::hex | ios::uppercase);
Jeff Thompson97223af2013-09-24 17:01:27 -070022 for (size_t i = 0; i < array.size(); ++i) {
Jeff Thompson10ad12a2013-09-24 16:19:11 -070023 uint8_t x = array[i];
Jeff Thompsona8d7b062013-08-08 15:56:35 -070024 if (x < 16)
25 result << '0';
26 result << (unsigned int)x;
27 }
28
29 return result.str();
30}
31
32}
33