9 #include "io/opensslBIO.h"
11 #define RECORD_HEADER_SIZE 17
15 enum class SignerCommand : uint16_t {
18 SET_SIGNATURE_TYPE = 0x10,
22 SET_OCSP_TARGET_CA = 0x14,
25 ADD_PROOF_LINE = 0x40,
32 GET_STATUS_REPORT = 0xD0
35 enum class SignerResult : uint16_t {
47 uint16_t command_count;
50 uint16_t payloadLength;
53 command( 0 ), flags( 0 ), sessid( 0 ), command_count( 0 ), totalLength( 0 ), offset( 0 ), payloadLength( 0 ) {
57 static void append( std::string& str, T val ) {
58 str.append( ( char * ) &val, sizeof( T ) );
62 static void read( std::string::const_iterator& it, T& val ) {
63 union typeConversion {
64 char buf[sizeof( T )];
67 typeConversion( const T& v ) : value( v ) {}
70 typeConversion data( 0 );
72 for( size_t i = 0; i < sizeof( T ); i++ ) {
79 std::string packToString() {
81 res.reserve( RECORD_HEADER_SIZE );
82 append( res, command );
84 append( res, sessid );
85 append( res, command_count );
86 append( res, totalLength );
87 append( res, offset );
88 append( res, payloadLength );
92 void unpackFromString( const std::string& str ) {
93 if( str.size() != RECORD_HEADER_SIZE ) {
94 throw std::runtime_error( "Invalid string length" );
97 auto it = str.cbegin();
101 read( it, command_count );
102 read( it, totalLength );
104 read( it, payloadLength );
106 bool isFollowupOf( const RecordHeader& head ) {
107 return head.command == command && head.flags == flags && head.sessid == sessid && head.command_count == command_count && head.totalLength == totalLength && head.offset + 1 == offset;
111 std::string parseCommand( RecordHeader& head, const std::string& input );
112 std::string parseCommandChunked( RecordHeader& head, std::shared_ptr<OpensslBIOWrapper> conn );
114 void sendCommand( RecordHeader& head, const std::string& data, std::shared_ptr<OpensslBIO> bio );