void checkKey( const char *value, // (I) 暗号化前のデータ const unsigned char *encrypted, // (I) 暗号化済みデータ const unsigned char *rsaString, // (I) 復号に必要な情報(秘密鍵) bool &ret ) // (O) 復号できることを保証できるか否か { if ( encrypted[0] ) { CString param; decodeParameter( param, (unsigned char *)encrypted, (unsigned char *)rsaString ); // param(暗号化済みデータを復号したもの) と bookmark.m_password (暗号 // 化する前のデータ) を照合し、両者が一致すれば、(復号可能な形で)暗号 // 化に成功しているものと判断する [復号に失敗する暗号化済みデータが生 // 成されることがあるため、暗号化済みデータが正常に復号できることをあ // らかじめ確認しておきたい] if ( (param.GetLength() == 0) || (param.Compare( value ) != 0) ) { ret = false; // 照合結果不一致 (この暗号化済みデータは採用でき // ない) } } }
std::shared_ptr<RPCStruct> RPCDecoder::decodeStruct(std::shared_ptr<std::vector<char>>& packet, uint32_t& position) { try { uint32_t structLength = _decoder.decodeInteger(packet, position); std::shared_ptr<RPCStruct> rpcStruct(new RPCStruct()); for(uint32_t i = 0; i < structLength; i++) { std::string name = _decoder.decodeString(packet, position); rpcStruct->insert(RPCStructElement(name, decodeParameter(packet, position))); } return rpcStruct; } catch(const std::exception& ex) { Output::printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what()); } catch(Exception& ex) { Output::printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what()); } catch(...) { Output::printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__); } return std::shared_ptr<RPCStruct>(); }
std::shared_ptr<RPCArray> RPCDecoder::decodeArray(std::shared_ptr<std::vector<char>>& packet, uint32_t& position) { try { uint32_t arrayLength = _decoder.decodeInteger(packet, position); std::shared_ptr<std::vector<std::shared_ptr<RPCVariable>>> array(new std::vector<std::shared_ptr<RPCVariable>>()); for(uint32_t i = 0; i < arrayLength; i++) { array->push_back(decodeParameter(packet, position)); } return array; } catch(const std::exception& ex) { Output::printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what()); } catch(Exception& ex) { Output::printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what()); } catch(...) { Output::printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__); } return std::shared_ptr<std::vector<std::shared_ptr<RPCVariable>>>(); }
void extractKey( CString ¶m, // (O) 復号済みデータ const unsigned char *encrypted, // (I) 復号したい(暗号化済み)データ const unsigned char *rsaString ) // (I) 復号に必要な情報(秘密鍵) { if ( encrypted[0] ) decodeParameter( param, (unsigned char *)encrypted, (unsigned char *)rsaString ); }
std::shared_ptr<RPCVariable> RPCDecoder::decodeResponse(std::shared_ptr<std::vector<char>> packet, uint32_t offset) { uint32_t position = offset + 8; std::shared_ptr<RPCVariable> response = decodeParameter(packet, position); if(packet->empty()) return response; //response is Void when packet is empty. if(packet->at(3) == 0xFF) { response->errorStruct = true; if(response->structValue->find("faultCode") == response->structValue->end()) response->structValue->insert(RPC::RPCStructElement("faultCode", std::shared_ptr<RPC::RPCVariable>(new RPC::RPCVariable(-1)))); if(response->structValue->find("faultString") == response->structValue->end()) response->structValue->insert(RPC::RPCStructElement("faultString", std::shared_ptr<RPC::RPCVariable>(new RPC::RPCVariable(std::string("undefined"))))); } return response; }
std::shared_ptr<std::vector<std::shared_ptr<RPCVariable>>> RPCDecoder::decodeRequest(std::shared_ptr<std::vector<char>> packet, std::string& methodName) { try { uint32_t position = 4; uint32_t headerSize = 0; if(packet->at(3) & 0x40) headerSize = _decoder.decodeInteger(packet, position) + 4; position = 8 + headerSize; methodName = _decoder.decodeString(packet, position); uint32_t parameterCount = _decoder.decodeInteger(packet, position); std::shared_ptr<std::vector<std::shared_ptr<RPCVariable>>> parameters(new std::vector<std::shared_ptr<RPCVariable>>()); if(parameterCount > 100) { Output::printError("Parameter count of RPC request is larger than 100."); return parameters; } for(uint32_t i = 0; i < parameterCount; i++) { parameters->push_back(decodeParameter(packet, position)); } return parameters; } catch(const std::exception& ex) { Output::printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what()); } catch(Exception& ex) { Output::printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what()); } catch(...) { Output::printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__); } return std::shared_ptr<std::vector<std::shared_ptr<RPCVariable>>>(); }
Nec1Decoder::Nec1Decoder(const IrReader &irReader) : IrDecoder() { unsigned int index = 0; boolean success; if (irReader.getDataLength() == 4U) { success = getDuration(irReader.getDuration(index++), 16U); if (!success) return; success = getDuration(irReader.getDuration(index++), 4U); if (!success) return; success = getDuration(irReader.getDuration(index++), 1U); if (!success) return; success = isEnding(irReader.getDuration(index)); if (!success) return; ditto = true; setValid(true); //strcpy_PF(decode, (uint_farptr_t) nec1DittoLiteral); // FIXME strcpy(decode, nec1DittoLiteral); // FIXME } else if (irReader.getDataLength() == 34U * 2U) { success = getDuration(irReader.getDuration(index++), 16U); if (!success) return; success = getDuration(irReader.getDuration(index++), 8U); if (!success) return; D = decodeParameter(irReader, index); if (D == invalid) return; index += 16; S = decodeParameter(irReader, index); if (S == invalid) return; index += 16; F = decodeParameter(irReader, index); if (F == invalid) return; index += 16; int invF = decodeParameter(irReader, index); if (invF < 0) return; if ((F ^ invF) != 0xFF) return; index += 16; success = getDuration(irReader.getDuration(index++), 1U); if (!success) return; success = isEnding(irReader.getDuration(index)); if (!success) return; ditto = false; setValid(true); //strncpy_PF(decode, pgm_read_byte(nec1DittoLiteral), 4); //strcpy_PF(decode, (uint_farptr_t) F("NEC1")); strcpy(decode, "NEC1"); char junk[5]; sprintf(junk, " %d", D); strcat(decode, junk); if (S != 255 - D) { sprintf(junk, " %d", S); strcat(decode, junk); } sprintf(junk, " %d", F); strcat(decode, junk); } }