monotone

monotone Mtn Source Tree

Root/constants.cc

1// Copyright (C) 2002 Graydon Hoare <graydon@pobox.com>
2//
3// This program is made available under the GNU GPL version 2.0 or
4// greater. See the accompanying file COPYING for details.
5//
6// This program is distributed WITHOUT ANY WARRANTY; without even the
7// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8// PURPOSE.
9
10// this file contains magic constants which you could, in theory, tweak.
11// probably best not to tweak them though.
12//
13// style notes: (1) scalar constants should be defined in constants.hh so
14// their values are visible to the compiler; (2) do not use std::string or
15// any other non-POD type for aggregate constants defined in this file, as
16// this tends to cause unnecessary copying and unconditionally-executed
17// initialization code for constants that don't get used always; (3) use
18// "char const foo[]" instead of "char const * const foo" -- it's less
19// typing and it saves an indirection.
20
21#include "base.hh"
22#include "constants.hh"
23
24namespace constants
25{
26 // all the ASCII characters (bytes) which are legal in a sequence of
27 // base64-encoded data. note that botan doesn't count \v or \f as
28 // whitespace (unlike <ctype.h>) and so neither do we.
29 char const legal_base64_bytes[] =
30 // base64 data characters
31 "abcdefghijklmnopqrstuvwxyz"
32 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
33 "0123456789+/="
34 // whitespace
35 " \r\n\t"
36 ;
37
38 // all the ASCII characters (bytes) which are legal in a SHA1 hex id
39 char const legal_id_bytes[] =
40 "0123456789abcdef"
41 ;
42
43 // all the ASCII characters (bytes) which can occur in cert names
44 char const legal_cert_name_bytes[] =
45 // LDH characters
46 "abcdefghijklmnopqrstuvwxyz"
47 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
48 "0123456789"
49 "-"
50 ;
51
52 // all the ASCII characters (bytes) which can occur in key names
53 char const legal_key_name_bytes[] =
54 // LDH characters
55 "abcdefghijklmnopqrstuvwxyz"
56 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
57 "0123456789"
58 "-"
59 // label and component separators
60 ".@"
61 // other non-shell, non-selector metacharacters allowed in (unquoted) local
62 // parts by RFC2821/RFC2822. The full list is !#$%&'*+-/=?^_`|{}~.
63 "+_"
64 ;
65
66 // merkle tree / netcmd / netsync related stuff
67 char const netsync_key_initializer[netsync_session_key_length_in_bytes]
68 = { 0 };
69
70 // attributes
71 char const encoding_attribute[] = "mtn:encoding";
72 char const manual_merge_attribute[] = "mtn:manual_merge";
73 char const binary_encoding[] = "binary";
74 char const default_encoding[] = "default";
75
76 // consistency checks - inside the namespace so we don't have to sprinkle
77 // constants:: all over them.
78}
79
80#include <boost/static_assert.hpp>
81
82// constraint checks for fundamental types
83// n.b. sizeof([unsigned] char) is *defined* to be 1 by the C++ standard.
84BOOST_STATIC_ASSERT(std::numeric_limits<unsigned char>::digits == 8);
85BOOST_STATIC_ASSERT(sizeof(u8) == 1);
86BOOST_STATIC_ASSERT(sizeof(u16) == 2);
87BOOST_STATIC_ASSERT(sizeof(u32) == 4);
88BOOST_STATIC_ASSERT(sizeof(u64) == 8);
89
90// constraint checks for relations between constants above
91using namespace constants;
92BOOST_STATIC_ASSERT(merkle_num_tree_levels > 0);
93BOOST_STATIC_ASSERT(merkle_num_tree_levels < 256);
94BOOST_STATIC_ASSERT(merkle_fanout_bits > 0);
95BOOST_STATIC_ASSERT(merkle_fanout_bits < 32);
96BOOST_STATIC_ASSERT(merkle_hash_length_in_bits > 0);
97BOOST_STATIC_ASSERT((merkle_hash_length_in_bits % merkle_fanout_bits) == 0);
98BOOST_STATIC_ASSERT(merkle_bitmap_length_in_bits > 0);
99BOOST_STATIC_ASSERT((merkle_bitmap_length_in_bits % 8) == 0);
100
101// Local Variables:
102// mode: C++
103// fill-column: 76
104// c-file-style: "gnu"
105// indent-tabs-mode: nil
106// End:
107// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status