| Remote Access Control | |||||
Definition at line 56 of file createrxhex.cpp.
Public Member Functions | |
| size_t | GetCounterSize () const |
| const std::string & | GetFilename () const |
| size_t | GetKeySize () const |
| size_t | GetMaxTransmitters () const |
| size_t | GetSerialNoSize () const |
| const std::vector< byte > & | GetSharedKey () const |
| std::string | GetSharedKeyString () const |
| ParameterParser (size_t argc, const char **argv) | |
| ~ParameterParser () | |
Private Member Functions | |
| std::string | CreateHexString (const std::vector< byte > &byteVector) const |
| std::vector< byte > | ParseHexString (const std::string &hexString) const |
Private Attributes | |
| size_t | m_counterSize |
| std::string | m_filename |
| size_t | m_keySize |
| size_t | m_maxTransmitters |
| size_t | m_serialNoSize |
| std::vector< byte > | m_sharedKey |
| ParameterParser::ParameterParser | ( | size_t | argc, | |
| const char ** | argv | |||
| ) |
Ctor taking the argc and argv parameters typically given to any main() function.
Definition at line 136 of file createrxhex.cpp.
References m_counterSize, m_filename, m_keySize, m_maxTransmitters, m_serialNoSize, m_sharedKey, and ParseHexString().
00137 { 00138 // Check that argument count is valid. 00139 if( argc != 7 ) { 00140 std::cout << "Parameters:\n" 00141 " filename - Filename for resulting Intel HEX file\n" 00142 " keysize - Size in bits of the AES secret and shared keys (128, 192 or 256)\n" 00143 " serialnosize - Size in bytes of the serial number (1, 2 or 4)\n" 00144 " countersize - Size in bytes of the sequential counter (1, 2 or 4)\n" 00145 " sharedkey - Hex representation of the shared key (32, 48 or 64 digits)\n" 00146 " maxtransmitters - Maximum number of associated transmitters\n" 00147 << std::endl; 00148 throw std::runtime_error( "Not exactly 6 parameters" ); 00149 } 00150 00151 // 00152 // Create strings or string streams from argument character arrays. 00153 // 00154 std::string arg1( argv[1] ); // Filename 00155 std::istringstream arg2( argv[2] ); // Key size 00156 std::istringstream arg3( argv[3] ); // Serial no size 00157 std::istringstream arg4( argv[4] ); // Counter size 00158 std::string arg5( argv[5] ); // Shared key 00159 std::istringstream arg6( argv[6] ); // Max transmitters 00160 00161 // 00162 // Copy string arguments and parse non-string arguments. 00163 // 00164 m_filename = arg1; 00165 00166 arg2 >> m_keySize; 00167 if( !arg2 ) { 00168 throw std::runtime_error( "Error parsing key size argument" ); 00169 } 00170 00171 arg3 >> m_serialNoSize; 00172 if( !arg3 ) { 00173 throw std::runtime_error( "Error parsing serial no size argument" ); 00174 } 00175 00176 arg4 >> m_counterSize; 00177 if( !arg4 ) { 00178 throw std::runtime_error( "Error parsing counter size argument" ); 00179 } 00180 00181 m_sharedKey = ParseHexString( arg5 ); 00182 00183 arg6 >> m_maxTransmitters; 00184 if( !arg6 ) { 00185 throw std::runtime_error( "Error parsing max transmitters argument" ); 00186 } 00187 00188 // 00189 // Check argument validity. 00190 // 00191 if( m_keySize != 128 && m_keySize != 192 && m_keySize != 256 ) { 00192 throw std::runtime_error( "Key size is not 128, 192 or 256 bits" ); 00193 } 00194 00195 if( m_serialNoSize != 1 && m_serialNoSize != 2 && m_serialNoSize != 4 ) { 00196 throw std::runtime_error( "Serial no is not 1, 2 or 4 bytes" ); 00197 } 00198 00199 if( m_counterSize != 1 && m_counterSize != 2 && m_counterSize != 4 ) { 00200 throw std::runtime_error( "Counter is not 1, 2 or 4 bytes" ); 00201 } 00202 00203 if( m_sharedKey.size() != m_keySize / 8 ) { 00204 throw std::runtime_error( "Shared key has invalid length" ); 00205 } 00206 }
Here is the call graph for this function:

| ParameterParser::~ParameterParser | ( | ) | [inline] |
| std::string ParameterParser::CreateHexString | ( | const std::vector< byte > & | byteVector | ) | const [private] |
Creates an HEX string from a vector of data bytes. Space between every two digits, ie. byte.
Definition at line 116 of file createrxhex.cpp.
Referenced by GetSharedKeyString().
00117 { 00118 std::ostringstream oss; 00119 oss << std::setfill('0') << std::hex; 00120 00121 // Add all byte last byte with spaces in between. 00122 for( size_t idx = 0; idx < byteVector.size() - 1; ++idx ) { 00123 oss << std::setw(2) << byteVector.at( idx ) << ' '; 00124 } 00125 00126 // Add last byte. 00127 if( byteVector.size() > 0 ) { 00128 oss << std::setw(2) << byteVector.at( byteVector.size()-1 ); 00129 } 00130 00131 return oss.str(); 00132 }
| size_t ParameterParser::GetCounterSize | ( | ) | const [inline] |
Definition at line 82 of file createrxhex.cpp.
References m_counterSize.
Referenced by CreateHEXFile(), and main().
00082 { return m_counterSize; }
| const std::string& ParameterParser::GetFilename | ( | ) | const [inline] |
Definition at line 79 of file createrxhex.cpp.
References m_filename.
Referenced by CreateHEXFile(), and main().
00079 { return m_filename; }
| size_t ParameterParser::GetKeySize | ( | ) | const [inline] |
Definition at line 80 of file createrxhex.cpp.
References m_keySize.
Referenced by CreateHEXFile(), and main().
00080 { return m_keySize; }
| size_t ParameterParser::GetMaxTransmitters | ( | ) | const [inline] |
Definition at line 84 of file createrxhex.cpp.
References m_maxTransmitters.
Referenced by CreateHEXFile(), and main().
00084 { return m_maxTransmitters; }
| size_t ParameterParser::GetSerialNoSize | ( | ) | const [inline] |
Definition at line 81 of file createrxhex.cpp.
References m_serialNoSize.
Referenced by CreateHEXFile(), and main().
00081 { return m_serialNoSize; }
| const std::vector< byte >& ParameterParser::GetSharedKey | ( | ) | const [inline] |
Definition at line 83 of file createrxhex.cpp.
References m_sharedKey.
Referenced by CreateHEXFile(), and GetSharedKeyString().
00083 { return m_sharedKey; }
| std::string ParameterParser::GetSharedKeyString | ( | ) | const [inline] |
Definition at line 86 of file createrxhex.cpp.
References CreateHexString(), and GetSharedKey().
Referenced by main().
00086 { return CreateHexString( GetSharedKey() ); }
Here is the call graph for this function:

| std::vector< byte > ParameterParser::ParseHexString | ( | const std::string & | hexString | ) | const [private] |
Parses an unformatted HEX number string. Must be pairs of HEX digits, ie. bytes.
Definition at line 91 of file createrxhex.cpp.
Referenced by ParameterParser().
00092 { 00093 // String must be even number of hex digits. 00094 if( hexString.size() % 2 != 0 ) { 00095 throw std::runtime_error( "Hex string does not have even character count" ); 00096 } 00097 00098 // 00099 // Parse hex digit pairs and insert into byte vector. 00100 // 00101 std::vector< byte > bytes; 00102 for( size_t idx = 0; idx < hexString.size(); idx += 2 ) { 00103 std::istringstream iss( hexString.substr( idx, 2 ) ); 00104 byte data; 00105 iss >> std::hex >> data; 00106 if( !iss ) { 00107 throw std::runtime_error( "Error parsing hex string \"" + hexString + "\"" ); 00108 } 00109 bytes.push_back( data ); 00110 } 00111 return bytes; 00112 }
size_t ParameterParser::m_counterSize [private] |
Stores synchronization counter size parameter.
Definition at line 62 of file createrxhex.cpp.
Referenced by GetCounterSize(), and ParameterParser().
std::string ParameterParser::m_filename [private] |
Stores filename parameter.
Definition at line 59 of file createrxhex.cpp.
Referenced by GetFilename(), and ParameterParser().
size_t ParameterParser::m_keySize [private] |
Stores key size parameter.
Definition at line 60 of file createrxhex.cpp.
Referenced by GetKeySize(), and ParameterParser().
size_t ParameterParser::m_maxTransmitters [private] |
Stores maximum number of transmitters parameter.
Definition at line 64 of file createrxhex.cpp.
Referenced by GetMaxTransmitters(), and ParameterParser().
size_t ParameterParser::m_serialNoSize [private] |
Stores serial number size parameter.
Definition at line 61 of file createrxhex.cpp.
Referenced by GetSerialNoSize(), and ParameterParser().
std::vector< byte > ParameterParser::m_sharedKey [private] |
Stores shared key parameter.
Definition at line 63 of file createrxhex.cpp.
Referenced by GetSharedKey(), and ParameterParser().
Generated on Fri Aug 8 11:02:28 2008 for AVR411 Secure Rolling Code Algorithm (PC Tools - createrxhex) by 1.4.7
|