XRootD
Loading...
Searching...
No Matches
XrdCryptoBasic Class Reference

#include <XrdCryptoBasic.hh>

+ Inheritance diagram for XrdCryptoBasic:
+ Collaboration diagram for XrdCryptoBasic:

Public Member Functions

 XrdCryptoBasic (const char *t=0, int l=0, const char *b=0)
 
virtual ~XrdCryptoBasic ()
 
virtual XrdSutBucketAsBucket ()
 
char * AsHexString ()
 
virtual char * Buffer () const
 
virtual int FromHex (const char *hex)
 
virtual int Length () const
 
virtual int SetBuffer (int l, const char *b)
 
virtual int SetLength (int l)
 
virtual int SetType (const char *t)
 
virtual char * Type () const
 
virtual void UseBuffer (int l, const char *b)
 

Detailed Description

Definition at line 47 of file XrdCryptoBasic.hh.

Constructor & Destructor Documentation

◆ XrdCryptoBasic()

XrdCryptoBasic::XrdCryptoBasic ( const char *  t = 0,
int  l = 0,
const char *  b = 0 
)

Definition at line 50 of file XrdCryptoBasic.cc.

51{
52 // Basic constructor.
53 // This class has responsibility over both its buffers.
54
55 type = 0;
56 membuf = 0;
57 lenbuf = 0;
58 //
59 // Fill in the type, if any
60 if (t) {
61 int tl = strlen(t);
62 if (tl) {
63 type = new char[tl+1];
64 if (type) {
65 memcpy(type,t,tl);
66 type[tl] = 0;
67 }
68 }
69 }
70 //
71 // Fill the buffer and length
72 if (l > 0) {
73 membuf = new char[l];
74 if (membuf) {
75 lenbuf = l;
76 if (b)
77 memcpy(membuf,b,l);
78 else
79 memset(membuf,0,l);
80 }
81 }
82}

◆ ~XrdCryptoBasic()

virtual XrdCryptoBasic::~XrdCryptoBasic ( )
inlinevirtual

Definition at line 53 of file XrdCryptoBasic.hh.

54 { if (type) delete[] type; if (membuf) delete[] membuf; }

Member Function Documentation

◆ AsBucket()

XrdSutBucket * XrdCryptoBasic::AsBucket ( )
virtual

Reimplemented in XrdCryptoCipher, and XrdCryptosslCipher.

Definition at line 85 of file XrdCryptoBasic.cc.

86{
87 // Return pointer to a bucket created using the internal buffer
88 // Type is not copied.
89 // The bucket is responsible for the allocated memory
90
91 XrdSutBucket *buck = (XrdSutBucket *)0;
92
93 if (Length()) {
94 char *nbuf = new char[Length()];
95 if (nbuf) {
96 memcpy(nbuf,Buffer(),Length());
97 buck = new XrdSutBucket(nbuf,Length());
98 }
99 }
100
101 return buck;
102}
virtual int Length() const
virtual char * Buffer() const

References Buffer(), and Length().

+ Here is the call graph for this function:

◆ AsHexString()

char * XrdCryptoBasic::AsHexString ( )

Definition at line 105 of file XrdCryptoBasic.cc.

106{
107 // Return the internal buffer as a hexadecimal string
108 static char out[XrdSutMAXBUF];
109
110 int lmax = XrdSutMAXBUF / 2 - 1 ;
111 int lconv = (Length() > lmax) ? lmax : Length();
112
113 if (!XrdSutToHex(Buffer(),lconv,&out[0]))
114 return &out[0];
115 return 0;
116}
int XrdSutToHex(const char *in, int lin, char *out)
Definition XrdSutAux.cc:235
#define XrdSutMAXBUF
Definition XrdSutAux.hh:48

References Buffer(), Length(), XrdSutMAXBUF, and XrdSutToHex().

Referenced by XrdCryptosslMsgDigest::Final(), and main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Buffer()

virtual char * XrdCryptoBasic::Buffer ( ) const
inlinevirtual

Definition at line 59 of file XrdCryptoBasic.hh.

59{ return membuf; }

Referenced by XrdCryptosslCipher::XrdCryptosslCipher(), XrdCryptosslCipher::XrdCryptosslCipher(), XrdCryptosslCipher::XrdCryptosslCipher(), AsBucket(), XrdCryptosslCipher::AsBucket(), AsHexString(), main(), XrdCryptoMsgDigest::operator==(), XrdSecProtocolgsi::Sign(), and XrdSecProtocolgsi::Verify().

+ Here is the caller graph for this function:

◆ FromHex()

int XrdCryptoBasic::FromHex ( const char *  hex)
virtual

Definition at line 119 of file XrdCryptoBasic.cc.

120{
121 // Set a binary buffer from a null-terminated hexadecimal string
122 // Returns 0 in case of success, -1 otherwise.
123
124 if (!hex)
125 return -1;
126
127 // Determine length
128 int lhex = strlen(hex);
129 int lout = lhex / 2;
130 if (lout * 2 < lhex) lout++;
131
132 // Allocate buffer
133 char *bout = new char[lout];
134 if (bout) {
135 if (XrdSutFromHex(hex, bout, lout) != 0) {
136 delete[] bout;
137 return -1;
138 }
139 UseBuffer(lout,bout);
140 return 0;
141 }
142
143 // Failure
144 return -1;
145}
int XrdSutFromHex(const char *in, char *out, int &lout)
Definition XrdSutAux.cc:268
virtual void UseBuffer(int l, const char *b)

References UseBuffer(), and XrdSutFromHex().

+ Here is the call graph for this function:

◆ Length()

virtual int XrdCryptoBasic::Length ( ) const
inlinevirtual

◆ SetBuffer()

int XrdCryptoBasic::SetBuffer ( int  l,
const char *  b 
)
virtual

Definition at line 188 of file XrdCryptoBasic.cc.

189{
190 // Substitute buffer with the l bytes at b.
191 // Returns 0 in case of success, -1 in case of error (in buffer allocation).
192
193 if (l > 0) {
194 //
195 // Allocate new buffer
196 char *tmpbuf = new char[l];
197 if (tmpbuf) {
198 if (b)
199 memcpy(tmpbuf,b,l);
200 else
201 memset(tmpbuf,0,l);
202 if (membuf)
203 delete[] membuf;
204 lenbuf = l;
205 membuf = tmpbuf;
206 } else
207 return -1;
208 } else {
209 //
210 // Release existing buffer, if any
211 if (membuf)
212 delete[] membuf;
213 lenbuf = 0;
214 membuf = 0;
215 }
216
217 return 0;
218}

Referenced by XrdCryptosslCipher::XrdCryptosslCipher(), XrdCryptosslCipher::XrdCryptosslCipher(), XrdCryptosslCipher::XrdCryptosslCipher(), XrdCryptosslCipher::XrdCryptosslCipher(), XrdCryptosslMsgDigest::Final(), XrdCryptosslCipher::Finalize(), and XrdCryptosslMsgDigest::Reset().

+ Here is the caller graph for this function:

◆ SetLength()

int XrdCryptoBasic::SetLength ( int  l)
virtual

Definition at line 148 of file XrdCryptoBasic.cc.

149{
150 // Truncate or enlarge the data buffer length to l; new bytes are filled
151 // with 0 in case of enlargement
152 // Returns 0 in case of success, -1 in case of error (in buffer allocation).
153
154 if (l > 0) {
155 //
156 // Create new buffer
157 char *newbuf = new char[l];
158 if (newbuf) {
159 //
160 // Save existing info
161 memcpy(newbuf,membuf,l);
162 //
163 // Reset additional bytes, if any
164 if (l > lenbuf)
165 memset(newbuf+lenbuf,0,(l-lenbuf));
166 //
167 // Release old buffer
168 delete[] membuf;
169 //
170 // Set the new length and buffer
171 lenbuf = l;
172 membuf = newbuf;
173 } else
174 return -1;
175 } else {
176 //
177 // Release existing buffer, if any
178 if (membuf)
179 delete[] membuf;
180 lenbuf = 0;
181 membuf = 0;
182 }
183
184 return 0;
185}

◆ SetType()

int XrdCryptoBasic::SetType ( const char *  t)
virtual

Definition at line 221 of file XrdCryptoBasic.cc.

222{
223 // Substitute type with the string at t.
224 // Returns 0 in case of success, -1 in case of error (in buffer allocation).
225
226 if (t) {
227 //
228 // Allocate new buffer
229 int tl = strlen(t);
230 char *tmpbuf = new char[tl+1];
231 if (tmpbuf) {
232 strcpy(tmpbuf,t);
233 delete[] type;
234 type = tmpbuf;
235 } else
236 return -1;
237 } else {
238 //
239 // Release existing buffer, if any
240 if (type)
241 delete[] type;
242 type = 0;
243 }
244
245 return 0;
246}

Referenced by XrdCryptosslCipher::XrdCryptosslCipher(), XrdCryptosslCipher::XrdCryptosslCipher(), XrdCryptosslCipher::XrdCryptosslCipher(), XrdCryptosslCipher::XrdCryptosslCipher(), XrdCryptosslCipher::XrdCryptosslCipher(), XrdCryptosslMsgDigest::XrdCryptosslMsgDigest(), and XrdCryptosslCipher::Finalize().

+ Here is the caller graph for this function:

◆ Type()

virtual char * XrdCryptoBasic::Type ( ) const
inlinevirtual

Definition at line 60 of file XrdCryptoBasic.hh.

60{ return type; }

Referenced by XrdCryptosslCipher::XrdCryptosslCipher(), XrdCryptosslCipher::AsBucket(), XrdCryptosslMsgDigest::Final(), and XrdCryptosslMsgDigest::Update().

+ Here is the caller graph for this function:

◆ UseBuffer()

virtual void XrdCryptoBasic::UseBuffer ( int  l,
const char *  b 
)
inlinevirtual

Definition at line 67 of file XrdCryptoBasic.hh.

68 { if (membuf) delete[] membuf; membuf = (char *)b; lenbuf = l; }

Referenced by XrdCryptosslCipher::XrdCryptosslCipher(), and FromHex().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: