9 #include "io/opensslBIO.h"
11 #define RECORD_HEADER_SIZE 17
15 enum class SignerCommand : uint16_t {
18 SET_SIGNATURE_TYPE = 0x10,
24 ADD_PROOF_LINE = 0x40,
31 GET_STATUS_REPORT = 0xD0
34 enum class SignerResult : uint16_t {
46 uint16_t command_count;
49 uint16_t payloadLength;
52 command( 0 ), flags( 0 ), sessid( 0 ), command_count( 0 ), totalLength( 0 ), offset( 0 ), payloadLength( 0 ) {
56 static void append( std::string& str, T val ) {
57 str.append( ( char* ) &val, sizeof( T ) );
61 static void read( std::string::const_iterator& it, T& val ) {
62 union typeConversion {
63 char buf[sizeof( T )];
66 typeConversion( const T& v ) : value( v ) {}
69 typeConversion data( 0 );
71 for( size_t i = 0; i < sizeof( T ); i++ ) {
78 std::string packToString() {
80 res.reserve( RECORD_HEADER_SIZE );
81 append( res, command );
83 append( res, sessid );
84 append( res, command_count );
85 append( res, totalLength );
86 append( res, offset );
87 append( res, payloadLength );
91 void unpackFromString( const std::string& str ) {
92 if( str.size() != RECORD_HEADER_SIZE ) {
93 throw std::runtime_error("Invalid string length");
96 auto it = str.cbegin();
100 read( it, command_count );
101 read( it, totalLength );
103 read( it, payloadLength );
105 bool isFollowupOf( const RecordHeader& head ) {
106 return head.command == command && head.flags == flags && head.sessid == sessid && head.command_count == command_count && head.totalLength == totalLength && head.offset + 1 == offset;
110 std::string parseCommand( RecordHeader& head, const std::string& input );
111 std::string parseCommandChunked( RecordHeader& head, std::shared_ptr<OpensslBIOWrapper> conn);
113 void sendCommand( RecordHeader& head, const std::string& data, std::shared_ptr<OpensslBIO> bio );