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);
31 * "context_handle": "########",
33 * "prf_in": "la la la input message",
34 * "desired_output_len": ####
38 bool GSSPseudoRandom::loadParameters ( JSONObject* params )
41 std::string sInputMessage;
50 if ( ! params->get("prf_key").isNull() )
52 if (params->get("prf_key").isInteger())
53 this->key = params->get("prf_key").integer();
55 throw std::invalid_argument( "Unrecognized argument type for prf_key." );
59 /**********************
60 * desired_output_len *
61 **********************/
62 if ( ! params->get("desired_output_len").isNull() )
64 if (params->get("desired_output_len").isInteger())
65 this->desiredOutputLength = params->get("desired_output_len").integer();
67 throw std::invalid_argument( "Unrecognized argument type for desired_output_len." );
74 if ( ! params->get("prf_in").isNull() )
76 if (params->get("prf_in").isString())
78 sInputMessage = params->get("prf_in").string();
79 this->inputMessage.setValue(sInputMessage);
87 if ( ! params->get("context_handle").isNull() )
89 if (params->get("context_handle").isString())
91 std::string contextKey = params->get("context_handle").string();
92 GSSContext ctx = GSSContextCache::instance()->retrieve(contextKey);
93 this->context = ctx.getContext();
103 void GSSPseudoRandom::execute()
106 gss_buffer_desc output_buf;
113 this->inputMessage.toGss(),
114 this->desiredOutputLength,
118 this->minor_status = minor;
119 this->outputMessage.setValue( (char *)output_buf.value, output_buf.length );
122 /* Desired JSON output:
125 * "command": "gss_pseudo_random",
130 * "random_bytes": "asdf"
134 JSONObject* GSSPseudoRandom::toJSON()
137 JSONObject *values = new JSONObject();
146 values->set("major_status", this->retVal);
147 values->set("minor_status", this->minor_status);
151 this->outputMessage.toString().c_str()