Fix integer precision warnings
[gssweb.git] / json_gssapi / src / commands / GSSPseudoRandom.cpp
index 48ea33d..b73dc95 100644 (file)
@@ -1,7 +1,34 @@
 /*
- * Copyright (c) 2014 <copyright holder> <email>
+ * Copyright (c) 2014, JANET(UK)
+ * All rights reserved.
  *
- * For license details, see the LICENSE file in the root of this project.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of JANET(UK) nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  */
 
@@ -12,7 +39,7 @@
 #include <datamodel/GSSContext.h>
 
 GSSPseudoRandom::GSSPseudoRandom(JSONObject *params, 
-                                              gss_pseudo_random_type fn) : GSSCommand(params)
+                                              gss_pseudo_random_type fn)
 {
   /* Variables */
   /* Error checking */
@@ -27,8 +54,6 @@ GSSPseudoRandom::GSSPseudoRandom(JSONObject *params,
 
 /* JSON input
  * 
- * {"method":    "gss_pseudo_random",
- *  "arguments": 
  *   {
  *     "context_handle":     "########",
  *     "prf_key":            ###,
@@ -49,10 +74,10 @@ bool GSSPseudoRandom::loadParameters ( JSONObject* params )
   /***********
    * prf_key *
    ***********/
-  if ( ! params->get("arguments").get("prf_key").isNull() )
+  if ( ! params->get("prf_key").isNull() )
   {
-    if (params->get("arguments").get("prf_key").isInteger())
-      this->key = params->get("arguments").get("prf_key").integer();
+    if (params->get("prf_key").isInteger())
+      this->key = (int )params->get("prf_key").integer();
     else
       throw std::invalid_argument( "Unrecognized argument type for prf_key." );
   }  
@@ -61,10 +86,10 @@ bool GSSPseudoRandom::loadParameters ( JSONObject* params )
   /**********************
    * desired_output_len *
    **********************/
-  if ( ! params->get("arguments").get("desired_output_len").isNull() )
+  if ( ! params->get("desired_output_len").isNull() )
   {
-    if (params->get("arguments").get("desired_output_len").isInteger())
-      this->desiredOutputLength = params->get("arguments").get("desired_output_len").integer();
+    if (params->get("desired_output_len").isInteger())
+      this->desiredOutputLength = (int )params->get("desired_output_len").integer();
     else
       throw std::invalid_argument( "Unrecognized argument type for desired_output_len." );
   }  
@@ -73,11 +98,11 @@ bool GSSPseudoRandom::loadParameters ( JSONObject* params )
   /**********
    * prf_in *
    **********/
-  if ( ! params->get("arguments").get("prf_in").isNull() )
+  if ( ! params->get("prf_in").isNull() )
   {
-    if (params->get("arguments").get("prf_in").isString())
+    if (params->get("prf_in").isString())
     {
-      sInputMessage = params->get("arguments").get("prf_in").string();
+      sInputMessage = params->get("prf_in").string();
       this->inputMessage.setValue(sInputMessage);
     }
   }
@@ -86,11 +111,11 @@ bool GSSPseudoRandom::loadParameters ( JSONObject* params )
   /******************
    * context_handle *
    ******************/
-  if ( ! params->get("arguments").get("context_handle").isNull() )
+  if ( ! params->get("context_handle").isNull() )
   {
-    if (params->get("arguments").get("context_handle").isString())
+    if (params->get("context_handle").isString())
     {
-      std::string contextKey = params->get("arguments").get("context_handle").string();
+      std::string contextKey = params->get("context_handle").string();
       GSSContext ctx = GSSContextCache::instance()->retrieve(contextKey);
       this->context = ctx.getContext();
     }
@@ -136,7 +161,6 @@ void GSSPseudoRandom::execute()
 JSONObject* GSSPseudoRandom::toJSON()
 {
   /* Variables */
-  JSONObject *ret = new JSONObject();
   JSONObject *values = new JSONObject();
   
   /* Error checking */
@@ -154,13 +178,9 @@ JSONObject* GSSPseudoRandom::toJSON()
     this->outputMessage.toString().c_str()
   );
   
-  // Put it all together.
-  ret->set("command", "gss_pseudo_random");
-  ret->set("return_values", *values);
-  
   /* Cleanup */
   
   /* Return */
-  return(ret);
+  return(values);
 }