2 * Copyright (c) 2014 <copyright holder> <email>
4 * For license details, see the LICENSE file in the root of this project.
10 #include "GSSPseudoRandom.h"
11 #include <cache/GSSContextCache.h>
12 #include <datamodel/GSSContext.h>
14 GSSPseudoRandom::GSSPseudoRandom(JSONObject *params,
15 gss_pseudo_random_type fn) : GSSCommand(params)
21 loadParameters(params);
30 * {"method": "gss_pseudo_random",
33 * "context_handle": "########",
35 * "prf_in": "la la la input message",
36 * "desired_output_len": ####
40 bool GSSPseudoRandom::loadParameters ( JSONObject* params )
43 std::string sInputMessage;
52 if ( ! params->get("arguments").get("prf_key").isNull() )
54 if (params->get("arguments").get("prf_key").isInteger())
55 this->key = params->get("arguments").get("prf_key").integer();
57 throw std::invalid_argument( "Unrecognized argument type for prf_key." );
61 /**********************
62 * desired_output_len *
63 **********************/
64 if ( ! params->get("arguments").get("desired_output_len").isNull() )
66 if (params->get("arguments").get("desired_output_len").isInteger())
67 this->desiredOutputLength = params->get("arguments").get("desired_output_len").integer();
69 throw std::invalid_argument( "Unrecognized argument type for desired_output_len." );
76 if ( ! params->get("arguments").get("prf_in").isNull() )
78 if (params->get("arguments").get("prf_in").isString())
80 sInputMessage = params->get("arguments").get("prf_in").string();
81 this->inputMessage.setValue(sInputMessage);
89 if ( ! params->get("arguments").get("context_handle").isNull() )
91 if (params->get("arguments").get("context_handle").isString())
93 std::string contextKey = params->get("arguments").get("context_handle").string();
94 GSSContext ctx = GSSContextCache::instance()->retrieve(contextKey);
95 this->context = ctx.getContext();
105 void GSSPseudoRandom::execute()
108 gss_buffer_desc output_buf;
115 this->inputMessage.toGss(),
116 this->desiredOutputLength,
120 this->minor_status = minor;
121 this->outputMessage.setValue( (char *)output_buf.value, output_buf.length );
124 /* Desired JSON output:
127 * "command": "gss_pseudo_random",
132 * "random_bytes": "asdf"
136 JSONObject* GSSPseudoRandom::toJSON()
139 JSONObject *ret = new JSONObject();
140 JSONObject *values = new JSONObject();
149 values->set("major_status", this->retVal);
150 values->set("minor_status", this->minor_status);
154 this->outputMessage.toString().c_str()
157 // Put it all together.
158 ret->set("command", "gss_pseudo_random");
159 ret->set("return_values", *values);