rearranging the commands into their own directory
[gssweb.git] / json_gssapi / src / commands / GSSUnwrap.cpp
1 /*
2  * Copyright (c) 2014 <copyright holder> <email>
3  *
4  * For license details, see the LICENSE file in the root of this project.
5  *
6  */
7
8 #include "GSSUnwrap.h"
9
10 GSSUnwrap::GSSUnwrap ( JSONObject* params, gss_unwrap_type fn )
11 {
12   function = fn;
13   loadParameters(params);
14 }
15
16 bool GSSUnwrap::loadParameters(JSONObject *params)
17 {
18   /* Variables */
19   std::string sInputMessage;
20   
21   /* Error checking */
22   /* Setup */
23   // Should I zeroOut?
24   
25   /* Main processing */
26   
27   /*****************
28    * input_message *
29    *****************/
30   if ( ! params->get("arguments").get("input_message").isNull() )
31   {
32     sInputMessage = params->get("arguments").get("input_message").string();
33     this->inputMessage.setValue(sInputMessage);
34   }
35   
36   /* Cleanup */
37   /* Return */
38   return true;
39 }
40
41
42 void GSSUnwrap::execute()
43 {
44   /* Variables */
45   gss_buffer_desc output_buf;
46   
47   retVal = function(
48     &(this->minor_status),
49     this->context,
50     this->inputMessage.toGss(),
51     &output_buf,
52     &(this->conf_state),
53     &(this->qop_state)
54   );
55   
56   this->outputMessage.setValue( (char *)output_buf.value, output_buf.length );
57 }
58
59 JSONObject* GSSUnwrap::toJSON()
60 {
61   /* Variables */
62   const char *conf_state;
63   JSONObject *ret = new JSONObject();
64   JSONObject *values = new JSONObject();
65   
66   /* Error checking */
67   
68   /* Setup */
69   
70   /* Main */
71   // Return Values
72   // Easy stuff
73   values->set("major_status", this->retVal);
74   values->set("minor_status", this->minor_status);
75   
76   values->set("qop_state", this->qop_state);
77   
78   conf_state = (this->conf_state) ? "TRUE" : "FALSE";
79   values->set("conf_state", conf_state);
80   
81   values->set(
82     "output_message",
83     this->outputMessage.toString().c_str()
84   );
85   
86   // Put it all together.
87   ret->set("command", "gss_wrap");
88   ret->set("return_values", *values);
89   
90   /* Cleanup */
91   
92   /* Return */
93   return(ret);
94 }