10 #define RECORD_HEADER_SIZE 17
14 enum class SignerCommand : uint16_t {
17 SET_SIGNATURE_TYPE = 0x10,
23 ADD_PROOF_LINE = 0x40,
30 GET_STATUS_REPORT = 0xD0
33 enum class SignerResult : uint16_t {
45 uint16_t command_count;
48 uint16_t payloadLength;
51 command( 0 ), flags( 0 ), sessid( 0 ), command_count( 0 ), totalLength( 0 ), offset( 0 ), payloadLength( 0 ) {
55 static void append( std::string& str, T val ) {
56 str.append( ( char* ) &val, sizeof( T ) );
60 static void read( std::string::const_iterator& it, T& val ) {
61 union typeConversion {
62 char buf[sizeof( T )];
65 typeConversion( const T& v ) : value( v ) {}
68 typeConversion data( 0 );
70 for( size_t i = 0; i < sizeof( T ); i++ ) {
77 std::string packToString() {
79 res.reserve( RECORD_HEADER_SIZE );
80 append( res, command );
82 append( res, sessid );
83 append( res, command_count );
84 append( res, totalLength );
85 append( res, offset );
86 append( res, payloadLength );
90 void unpackFromString( const std::string& str ) {
91 if( str.size() != RECORD_HEADER_SIZE ) {
92 throw "Invalid string length";
95 auto it = str.cbegin();
99 read( it, command_count );
100 read( it, totalLength );
102 read( it, payloadLength );
107 std::string parseCommand( RecordHeader& head, const std::string& input, std::shared_ptr<std::ostream> log );
109 void sendCommand( RecordHeader& head, const std::string& data, std::shared_ptr<OpensslBIO> bio, std::shared_ptr<std::ostream> log );