~ubuntu-branches/ubuntu/precise/botan1.8/precise

« back to all changes in this revision

Viewing changes to src/utils/scan_name.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2009-08-04 00:47:32 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090804004732-bmf7f33nfoctocbz
Tags: 1.8.5-1
* Merging upstream version 1.8.5.
* Adding old changelog entries for separately uploaded botan packages
  in the past.
* Using correct rfc-2822 date formats in changelog.
* Wrapping build depends.
* Adding misc depends.
* Renaming local manpages directory to common name.
* Minimizing rules file.
* Doing some minor cosmetical updates in the manpage.
* Updating copyright file to reflect changes of upstream version
  1.8.0.
* Using new configure.py instread of configure.pl, updating necessary
  things to cope with that.
* Updating.
* Tidy debhelper install files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
SCAN Name Abstraction
3
 
(C) 2008 Jack Lloyd
4
 
*
5
 
* Distributed under the terms of the Botan license
6
 
*/
7
 
 
8
 
#include <botan/scan_name.h>
9
 
#include <botan/parsing.h>
10
 
#include <botan/libstate.h>
11
 
#include <stdexcept>
12
 
 
13
 
namespace Botan {
14
 
 
15
 
namespace {
16
 
 
17
 
std::vector<std::string>
18
 
parse_and_deref_aliases(const std::string& algo_spec)
19
 
   {
20
 
   std::vector<std::string> parts = parse_algorithm_name(algo_spec);
21
 
   std::vector<std::string> out;
22
 
 
23
 
   for(size_t i = 0; i != parts.size(); ++i)
24
 
      {
25
 
      std::string part_i = global_state().deref_alias(parts[i]);
26
 
 
27
 
      if(i == 0 && part_i.find_first_of(",()") != std::string::npos)
28
 
         {
29
 
         std::vector<std::string> parts_i = parse_and_deref_aliases(part_i);
30
 
 
31
 
         for(size_t j = 0; j != parts_i.size(); ++j)
32
 
            out.push_back(parts_i[j]);
33
 
         }
34
 
      else
35
 
         out.push_back(part_i);
36
 
      }
37
 
 
38
 
   return out;
39
 
   }
40
 
 
41
 
}
42
 
 
43
 
SCAN_Name::SCAN_Name(const std::string& algo_spec)
44
 
   {
45
 
   orig_algo_spec = algo_spec;
46
 
 
47
 
   name = parse_and_deref_aliases(algo_spec);
48
 
 
49
 
   if(name.size() == 0)
50
 
      throw Decoding_Error("Bad SCAN name " + algo_spec);
51
 
   }
52
 
 
53
 
std::string SCAN_Name::arg(u32bit i) const
54
 
   {
55
 
   if(i >= arg_count())
56
 
      throw std::range_error("SCAN_Name::argument");
57
 
   return name[i+1];
58
 
   }
59
 
 
60
 
std::string SCAN_Name::arg(u32bit i, const std::string& def_value) const
61
 
   {
62
 
   if(i >= arg_count())
63
 
      return def_value;
64
 
   return name[i+1];
65
 
   }
66
 
 
67
 
u32bit SCAN_Name::arg_as_u32bit(u32bit i, u32bit def_value) const
68
 
   {
69
 
   if(i >= arg_count())
70
 
      return def_value;
71
 
   return to_u32bit(name[i+1]);
72
 
   }
73
 
 
74
 
}