00001 #ifndef COMMON_TRUENAME_HXX 00002 #define COMMON_TRUENAME_HXX 00003 00004 /* 00005 * Copyright (c) 2004, The EROS Group, LLC and Johns Hopkins 00006 * University. All rights reserved. 00007 * 00008 * This software was developed to support the EROS secure operating 00009 * system project (http://www.eros-os.org). The latest version of 00010 * the OpenCM software can be found at http://www.opencm.org. 00011 * 00012 * Redistribution and use in source and binary forms, with or 00013 * without modification, are permitted provided that the following 00014 * conditions are met: 00015 * 00016 * 1. Redistributions of source code must retain the above copyright 00017 * notice, this list of conditions and the following disclaimer. 00018 * 00019 * 2. Redistributions in binary form must reproduce the above 00020 * copyright notice, this list of conditions and the following 00021 * disclaimer in the documentation and/or other materials 00022 * provided with the distribution. 00023 * 00024 * 3. Neither the name of the The EROS Group, LLC nor the name of 00025 * Johns Hopkins University, nor the names of its contributors 00026 * may be used to endorse or promote products derived from this 00027 * software without specific prior written permission. 00028 * 00029 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 00030 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 00031 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00032 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00033 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 00034 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00035 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 00036 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00037 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 00038 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00039 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00040 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00041 * POSSIBILITY OF SUCH DAMAGE. 00042 */ 00043 00044 struct OPENCM_SHA; 00045 00046 /* This structure really ought to be opaque, but the binary 00047 serialization logic effectively needs to know all of it. */ 00048 enum TrueNameKind { 00049 TNK_NULL = 0, /* Reserved for serialization! */ 00050 TNK_SHA1 = 1, 00051 TNK_NID = 2, 00052 TNK_CFG = 3 00053 }; 00054 00055 #define SHA1_PREFIX "sha1" 00056 #define NID_PREFIX "nid" 00057 00058 #define TNV_MAXLEN 20 00059 struct TrueName { 00060 public: 00061 struct BoolConversionSupport { 00062 int dummy; 00063 }; 00064 00065 uint8_t kind; 00066 ByteString value; 00067 00068 static size_t repLen(uint8_t kind); 00069 static std::string NewName(); 00070 00071 hash32_t hash(); 00072 std::string asHumanString() const; 00073 std::string asStringOldFormat() const; 00074 00075 private: 00076 void set_from_sha(const OpenSHA& sha); 00077 00078 public: 00079 TrueName() 00080 { 00081 kind = TNK_NULL; 00082 } 00083 00084 TrueName(TrueNameKind k) 00085 { 00086 kind = k; 00087 } 00088 00089 TrueName(const TrueName& tn); 00090 TrueName(const OpenSHA& sha); 00091 TrueName(uint32_t len, const void *s); 00092 00093 static TrueName OfString(std::string); 00094 00095 int cmp(const TrueName& tn); 00096 bool operator==(const TrueName& tn); 00097 bool operator!=(const TrueName& tn) 00098 { 00099 return !(*this == tn); 00100 } 00101 00103 inline operator int BoolConversionSupport::* () const 00104 { 00105 return (kind == TNK_NULL) ? 0 : &BoolConversionSupport::dummy; 00106 } 00107 00108 // Support for trees and maps: 00109 bool operator<(const TrueName& other) const 00110 { 00111 if (kind < other.kind) 00112 return true; 00113 if (kind > other.kind) 00114 return false; 00115 00116 return value < other.value; 00117 } 00118 00119 bool operator>(const TrueName& other) const 00120 { 00121 if (kind > other.kind) 00122 return true; 00123 if (kind > other.kind) 00124 return false; 00125 00126 return value > other.value; 00127 } 00128 00129 static TrueName Null; 00130 static TrueName CfgDir; 00131 }; 00132 00133 // Local Variables: 00134 // mode:c++ 00135 // End: 00136 00137 #endif /* COMMON_TRUENAME_HXX */
1.4.6