int main(int argc,char *argv[]) { if (argc==2 && (strcmp(argv[1],"-help")==0)) { showHelp(); return 0; } if (argc!=4) { Warning("Zle zadane argumenty\n"); showHelp(); return 1; } struct ppm *ppmFile=ppm_read(argv[1]); if (ppmFile==NULL) { FatalError("Chyba citania zo suboru"); return 1; } EncodeMessage(ppmFile,argv[3]); if (ppm_write(ppmFile,argv[2])!=0) { free(ppmFile); Warning("Zapis do suboru sa nepodaril"); return 1; } free(ppmFile); return 0; }
void EncodeAndDecodeMessage(LPWSTR pwszSignerName) { CRYPT_DATA_BLOB EncodedBlob; if(EncodeMessage(&EncodedBlob, pwszSignerName)) { DecodeMessage(&EncodedBlob, pwszSignerName); } }
int CCliReq::EncodeMessage(std::vector<char>& a_vecData) { int nRet = RESULT_OK; std::string strData; nRet = EncodeMessage(strData); if(nRet != RESULT_OK){ return nRet; } a_vecData.clear(); a_vecData.insert(a_vecData.end(), strData.begin(), strData.end()); return RESULT_OK; }
void msg_test(wchar_t const*const subject_str){ CRYPT_DATA_BLOB data_blob = { 0 }; EncodeMessage(&data_blob, const_cast<wchar_t*>( subject_str) ); std::ofstream o_cert( "c:\\temp\\signed_message.p7b", std::ios_base::out | std::ios_base::binary ); o_cert.write( reinterpret_cast<char const*>(data_blob.pbData), data_blob.cbData ); o_cert.flush(); assert( !o_cert.bad() ); DecodeMessage(&data_blob, const_cast<wchar_t*>( subject_str) ); }
CStmApi::eResult CStmReqApi::EncodeMessage(char *a_chData, unsigned int a_nMaxLen, unsigned int *a_nDataLen) { CStmApi::eResult nRet = RESULT_OK; std::string strData; nRet = EncodeMessage(strData); if(nRet != RESULT_OK){ return nRet; } if(strData.size() > a_nMaxLen){ return RESULT_BUFFER_TOO_SMALL; } strncpy(a_chData, strData.c_str(), strData.size()); *a_nDataLen = strData.size(); return RESULT_OK; }
static void CallServiceMethodDone( boost::shared_ptr<Connection> connection, const ProtobufDecoder *decoder, boost::shared_ptr<google::protobuf::Message> resource, boost::shared_ptr<google::protobuf::Message> response) { VLOG(2) << connection->name() << " : " << "HandleService->CallServiceMethodDone()"; CHECK(decoder != NULL); const ProtobufLineFormat::MetaData &request_meta = decoder->meta(); ProtobufLineFormat::MetaData response_meta; response_meta.set_type(ProtobufLineFormat::MetaData::RESPONSE); response_meta.set_identify(request_meta.response_identify()); CHECK(response->AppendToString(response_meta.mutable_content())) << "Fail to serialize response for requst: "; EncodeData data = EncodeMessage(&response_meta); if (!connection->PushData(data)) { delete data.first; delete data.second; } if (!connection->ScheduleWrite()) { delete data.first; delete data.second; } }
int TnmSnmpEncode(Tcl_Interp *interp, TnmSnmp *session, TnmSnmpPdu *pdu, TnmSnmpRequestProc *proc, ClientData clientData) { int retry = 0, packetlen = 0, code = 0; u_char packet[TNM_SNMP_MAXSIZE]; TnmBer *ber; memset((char *) packet, 0, sizeof(packet)); /* * Some special care must be taken to conform to SNMPv1 sessions: * SNMPv2 getbulk requests must be turned into getnext requests * and SNMPv2 error codes must be mapped on SNMPv1 error codes * (e.g. genErr as nothing more appropriate is available). * * This is based on the mapping presented in Marhall Rose and * Keith McCloghrie: "How to Manage your Network using SNMP" * page 95. */ if (session->version == TNM_SNMPv1) { if (pdu->type == ASN1_SNMP_GETBULK) { pdu->type = ASN1_SNMP_GETNEXT; pdu->errorStatus = TNM_SNMP_NOERROR; pdu->errorIndex = 0; } if (pdu->type == ASN1_SNMP_INFORM || pdu->type == ASN1_SNMP_TRAP2) { pdu->type = ASN1_SNMP_TRAP1; } if (pdu->errorStatus > TNM_SNMP_GENERR) { switch (pdu->errorStatus) { case TNM_SNMP_NOACCESS: case TNM_SNMP_NOCREATION: case TNM_SNMP_AUTHORIZATIONERROR: case TNM_SNMP_NOTWRITABLE: case TNM_SNMP_INCONSISTENTNAME: pdu->errorStatus = TNM_SNMP_NOSUCHNAME; break; case TNM_SNMP_WRONGTYPE: case TNM_SNMP_WRONGLENGTH: case TNM_SNMP_WRONGENCODING: case TNM_SNMP_WRONGVALUE: case TNM_SNMP_INCONSISTENTVALUE: pdu->errorStatus = TNM_SNMP_BADVALUE; break; case TNM_SNMP_RESOURCEUNAVAILABLE: case TNM_SNMP_COMMITFAILED: case TNM_SNMP_UNDOFAILED: pdu->errorStatus = TNM_SNMP_GENERR; break; default: pdu->errorStatus = TNM_SNMP_GENERR; break; } } } /* * Encode message into ASN1 BER transfer syntax. Authentication or * encryption is done within the following procedures if it is an * authentic or private message. */ ber = TnmBerCreate(packet, sizeof(packet)); code = EncodeMessage(interp, session, pdu, ber); if (code != TCL_OK) { TnmBerDelete(ber); return TCL_ERROR; } packetlen = TnmBerSize(ber); TnmBerDelete(ber); switch (pdu->type) { case ASN1_SNMP_GET: tnmSnmpStats.snmpOutGetRequests++; break; case ASN1_SNMP_GETNEXT: tnmSnmpStats.snmpOutGetNexts++; break; case ASN1_SNMP_SET: tnmSnmpStats.snmpOutSetRequests++; break; case ASN1_SNMP_RESPONSE: tnmSnmpStats.snmpOutGetResponses++; break; case ASN1_SNMP_TRAP1: tnmSnmpStats.snmpOutTraps++; break; } /* * Show the contents of the PDU - mostly for debugging. */ TnmSnmpEvalBinding(interp, session, pdu, TNM_SNMP_SEND_EVENT); TnmSnmpDumpPDU(interp, pdu); /* * A trap message or a response? - send it and we are done! */ if (pdu->type == ASN1_SNMP_TRAP1 || pdu->type == ASN1_SNMP_TRAP2 || pdu->type == ASN1_SNMP_RESPONSE || pdu->type == ASN1_SNMP_REPORT) { #ifdef TNM_SNMPv2U if (session->version == TNM_SNMPv2U) { TnmSnmpUsecAuth(session, packet, packetlen); } #endif code = TnmSnmpSend(interp, session, packet, packetlen, &pdu->addr, TNM_SNMP_ASYNC); if (code != TCL_OK) { return TCL_ERROR; } Tcl_ResetResult(interp); return TCL_OK; } /* * Asychronous request: queue request and we are done. */ if (proc) { TnmSnmpRequest *rPtr; rPtr = TnmSnmpCreateRequest(pdu->requestId, packet, packetlen, proc, clientData, interp); TnmSnmpQueueRequest(session, rPtr); Tcl_SetObjResult (interp, Tcl_NewIntObj (pdu->requestId)); return TCL_OK; } /* * Synchronous request: send packet and wait for response. */ for (retry = 0; retry <= session->retries; retry++) { int id, status, index; #ifdef TNM_SNMP_BENCH TnmSnmpMark stats; memset((char *) &stats, 0, sizeof(stats)); #endif repeat: #ifdef TNM_SNMPv2U if (session->version == TNM_SNMPv2U) { TnmSnmpUsecAuth(session, packet, packetlen); } #endif TnmSnmpDelay(session); code = TnmSnmpSend(interp, session, packet, packetlen, &pdu->addr, TNM_SNMP_SYNC); if (code != TCL_OK) { return TCL_ERROR; } #ifdef TNM_SNMP_BENCH if (stats.sendSize == 0) { stats.sendSize = tnmSnmpBenchMark.sendSize; stats.sendTime = tnmSnmpBenchMark.sendTime; } #endif while (TnmSnmpWait(session->timeout * 1000 / (session->retries + 1), TNM_SNMP_SYNC) > 0) { u_char packet[TNM_SNMP_MAXSIZE]; int rc, packetlen = TNM_SNMP_MAXSIZE; struct sockaddr_in from; code = TnmSnmpRecv(interp, packet, &packetlen, &from, TNM_SNMP_SYNC); if (code != TCL_OK) { return TCL_ERROR; } rc = TnmSnmpDecode(interp, packet, packetlen, &from, session, &id, &status, &index); if (rc == TCL_BREAK) { if (retry++ <= session->retries + 1) { goto repeat; } } if (rc == TCL_OK) { if (id == pdu->requestId) { #ifdef TNM_SNMP_BENCH stats.recvSize = tnmSnmpBenchMark.recvSize; stats.recvTime = tnmSnmpBenchMark.recvTime; session->stats = stats; #endif return TCL_OK; } rc = TCL_CONTINUE; } if (rc == TCL_CONTINUE) { if (hexdump) { fprintf(stderr, "%s\n", Tcl_GetStringResult(interp)); } continue; } if (rc == TCL_ERROR) { pdu->errorStatus = status; pdu->errorIndex = index; return TCL_ERROR; } } } Tcl_SetResult(interp, "noResponse 0 {}", TCL_STATIC); return TCL_ERROR; }