xrootd
XrdCryptoRSA.hh
Go to the documentation of this file.
1 // $Id$
2 #ifndef __CRYPTO_RSA_H__
3 #define __CRYPTO_RSA_H__
4 /******************************************************************************/
5 /* */
6 /* X r d C r y p t o R S A . h h */
7 /* */
8 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */
9 /* All Rights Reserved. See XrdInfo.cc for complete License Terms */
10 /* Produced by Andrew Hanushevsky for Stanford University under contract */
11 /* DE-AC03-76-SFO0515 with the Department of Energy */
12 /******************************************************************************/
13 
14 /* ************************************************************************** */
15 /* */
16 /* Abstract interface for RSA PKI functionality. */
17 /* Allows to plug-in modules based on different crypto implementation */
18 /* (OpenSSL, Botan, ...) */
19 /* */
20 /* ************************************************************************** */
21 
22 #include <XrdSut/XrdSutBucket.hh>
23 #include <XrdOuc/XrdOucString.hh>
25 
26 typedef void * XrdCryptoRSAdata;
27 
28 // ---------------------------------------------------------------------------//
29 //
30 // RSA interface
31 //
32 // ---------------------------------------------------------------------------//
34 {
35 public:
37  virtual ~XrdCryptoRSA() {}
38 
39  // Status
40  enum ERSAStatus { kInvalid = 0, kPublic = 1, kComplete = 2};
42  const char *Status(ERSAStatus t = kInvalid) const
43  { return ((t == kInvalid) ? cstatus[status] : cstatus[t]); }
44 
45  // Access underlying data (in opaque form)
46  virtual XrdCryptoRSAdata Opaque();
47 
48  // Dump information
49  virtual void Dump();
50 
51  // Validity
52  bool IsValid() { return (status != kInvalid); }
53 
54  // Output lengths
55  virtual int GetOutlen(int lin); // Length of encrypted buffers
56  virtual int GetPublen(); // Length of export public key
57  virtual int GetPrilen(); // Length of export private key
58 
59  // Import / Export methods
60  virtual int ImportPublic(const char *in, int lin);
61  virtual int ExportPublic(char *out, int lout);
62  int ExportPublic(XrdOucString &exp);
63  virtual int ImportPrivate(const char *in, int lin);
64  virtual int ExportPrivate(char *out, int lout);
65  int ExportPrivate(XrdOucString &exp);
66 
67  // Encryption / Decryption methods
68  virtual int EncryptPrivate(const char *in, int lin, char *out, int lout);
69  virtual int DecryptPublic(const char *in, int lin, char *out, int lout);
70  virtual int EncryptPublic(const char *in, int lin, char *out, int lout);
71  virtual int DecryptPrivate(const char *in, int lin, char *out, int lout);
72  int EncryptPrivate(XrdSutBucket &buck);
73  int DecryptPublic (XrdSutBucket &buck);
74  int EncryptPublic (XrdSutBucket &buck);
75  int DecryptPrivate(XrdSutBucket &buck);
76 
77 private:
78  static const char *cstatus[3]; // Names of status
79 };
80 
81 #endif