Jeff Thompson | c057343 | 2013-09-19 17:41:36 -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: Jeff Thompson <jefft0@remap.ucla.edu> |
| 5 | * See COPYING for copyright and distribution information. |
| 6 | */ |
| 7 | |
| 8 | #include <stdlib.h> |
| 9 | #include <sstream> |
| 10 | |
Jeff Thompson | 25b4e61 | 2013-10-10 16:03:24 -0700 | [diff] [blame^] | 11 | #include <ndn-cpp/security/certificate/oid.hpp> |
Jeff Thompson | c057343 | 2013-09-19 17:41:36 -0700 | [diff] [blame] | 12 | |
| 13 | using namespace std; |
| 14 | |
| 15 | namespace ndn { |
| 16 | |
| 17 | OID::OID(const string& oid) |
| 18 | { |
| 19 | string str = oid + "."; |
| 20 | |
| 21 | size_t pos = 0; |
| 22 | size_t ppos = 0; |
| 23 | |
| 24 | while(string::npos != pos){ |
| 25 | ppos = pos; |
| 26 | |
| 27 | pos = str.find_first_of('.', pos); |
| 28 | if(pos == string::npos) |
| 29 | break; |
| 30 | |
| 31 | oid_.push_back(atoi(str.substr(ppos, pos - ppos).c_str())); |
| 32 | |
| 33 | pos++; |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | string OID::toString() |
| 38 | { |
| 39 | ostringstream convert; |
| 40 | |
| 41 | vector<int>::iterator it = oid_.begin(); |
| 42 | for(; it < oid_.end(); it++){ |
| 43 | if(it != oid_.begin()) |
| 44 | convert << "."; |
| 45 | convert << *it; |
| 46 | } |
| 47 | |
| 48 | return convert.str(); |
| 49 | } |
| 50 | |
| 51 | bool OID::equal(const OID& oid) |
| 52 | { |
| 53 | vector<int>::const_iterator i = oid_.begin(); |
| 54 | vector<int>::const_iterator j = oid.oid_.begin(); |
| 55 | |
| 56 | for (; i != oid_.end () && j != oid.oid_.end (); i++, j++) { |
| 57 | if(*i != *j) |
| 58 | return false; |
| 59 | } |
| 60 | |
| 61 | if (i == oid_.end () && j == oid.oid_.end ()) |
| 62 | return true; |
| 63 | else |
| 64 | return false; |
| 65 | } |
| 66 | |
| 67 | } |