~ubuntu-branches/ubuntu/intrepid/kdebluetooth/intrepid-proposed

« back to all changes in this revision

Viewing changes to kdebluetooth/libqobex/qobex/qobexauth.h

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Mercatante
  • Date: 2008-08-07 09:49:47 UTC
  • mto: This revision was merged to the branch mainline in revision 56.
  • Revision ID: james.westby@ubuntu.com-20080807094947-pj6q3uxwuv7l844q
Tags: upstream-0.1
ImportĀ upstreamĀ versionĀ 0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
    This file is part of libqobex.
3
 
 
4
 
    Copyright (c) 2003 Mathias Froehlich <Mathias.Froehlich@web.de>
5
 
 
6
 
    This library is free software; you can redistribute it and/or
7
 
    modify it under the terms of the GNU Library General Public
8
 
    License as published by the Free Software Foundation; either
9
 
    version 2 of the License, or (at your option) any later version.
10
 
 
11
 
    This library is distributed in the hope that it will be useful,
12
 
    but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 
    Library General Public License for more details.
15
 
 
16
 
    You should have received a copy of the GNU Library General Public License
17
 
    along with this library; see the file COPYING.LIB.  If not, write to
18
 
    the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
19
 
    Boston, MA 02110-1301, USA.
20
 
*/
21
 
 
22
 
#ifndef QOBEXAUTH_H
23
 
#define QOBEXAUTH_H
24
 
 
25
 
#include <qcstring.h>
26
 
 
27
 
#include "qobexlengthvaluebase.h"
28
 
 
29
 
class QObexAuthDigestBase
30
 
  : public QObexLengthValueBase {
31
 
protected:
32
 
  enum {
33
 
    Realm_ASCII = 0,
34
 
    Realm_ISO_8859_1 = 1,
35
 
    Realm_ISO_8859_2 = 2,
36
 
    Realm_ISO_8859_3 = 3,
37
 
    Realm_ISO_8859_4 = 4,
38
 
    Realm_ISO_8859_5 = 5,
39
 
    Realm_ISO_8859_6 = 6,
40
 
    Realm_ISO_8859_7 = 7,
41
 
    Realm_ISO_8859_8 = 8,
42
 
    Realm_ISO_8859_9 = 9,
43
 
    Realm_UNICODE = 255
44
 
  };
45
 
 
46
 
  QObexAuthDigestBase( const QByteArray& d ) : QObexLengthValueBase( d ) {}
47
 
  QObexAuthDigestBase() {}
48
 
 
49
 
  void appendStringValue( Q_UINT8 tag, const QString& s );
50
 
  QString getStringTag( Q_UINT8 tag ) const;
51
 
 
52
 
  static QByteArray computeDigest( const QByteArray&, const QByteArray& );
53
 
  // returns a random bytearray
54
 
  static QByteArray randomNonce();
55
 
  static QString toString( const QByteArray& );
56
 
 
57
 
  struct text_encoding {
58
 
    const char* name;
59
 
    Q_UINT8 tag;
60
 
  };
61
 
  static text_encoding encoding_list[];
62
 
};
63
 
 
64
 
class QObexAuthDigestChallenge
65
 
  : public QObexAuthDigestBase {
66
 
public:
67
 
  enum {
68
 
    NonceTag = 0,
69
 
    OptionsTag = 1,
70
 
    RealmTag = 2,
71
 
 
72
 
    SendUserId = 0x1,
73
 
    AccessReadOnly = 0x2
74
 
  };
75
 
 
76
 
  struct AuthInfo {
77
 
    QString realm;
78
 
    Q_UINT8 options;
79
 
    AuthInfo() : options( 0 ) {}
80
 
    AuthInfo( const QString& r ) : realm( r ), options( 0 ) {}
81
 
    AuthInfo( Q_UINT8 o ) : options( o ) {}
82
 
    AuthInfo( const QString& r, Q_UINT8 o ) : realm( r ), options( o ) {}
83
 
  };
84
 
 
85
 
  // Constructor to create data for a new AuthChallenge header.
86
 
  QObexAuthDigestChallenge( const AuthInfo& );
87
 
  // Constructor used to parse the data given here.
88
 
  QObexAuthDigestChallenge( const QByteArray& );
89
 
  // Needed for list handling.
90
 
  QObexAuthDigestChallenge();
91
 
 
92
 
  // Read access to the fields of the header data.
93
 
  QByteArray nonce() const;
94
 
  QString realm() const;
95
 
  bool hasRealm() const;
96
 
  int options() const;
97
 
  bool readOnly() const;
98
 
  bool userIdRequired() const;
99
 
  bool hasOptions() const;
100
 
 
101
 
  /**
102
 
   */
103
 
  QString toString( int indent ) const;
104
 
};
105
 
 
106
 
class QObexAuthDigestResponse
107
 
  : public QObexAuthDigestBase {
108
 
public:
109
 
  enum {
110
 
    RequestDigestTag = 0,
111
 
    UserIdTag = 1,
112
 
    NonceTag = 2,
113
 
 
114
 
    SendUserId = 0x1,
115
 
    AccessReadOnly = 0x2
116
 
  };
117
 
 
118
 
  struct AuthInfo {
119
 
    QByteArray secret;
120
 
    QString userId;
121
 
    AuthInfo() {}
122
 
    AuthInfo( const QByteArray& s ) : secret( s ) {}
123
 
    AuthInfo( const QString& u ) : userId( u ) {}
124
 
    AuthInfo( const QByteArray& s, const QString& u ) : secret( s ), userId( u ) {}
125
 
  };
126
 
 
127
 
  // Constructor to create data for a new AuthResponse header.
128
 
  QObexAuthDigestResponse( const QByteArray&, const AuthInfo& );
129
 
  // Constructor used to parse the data given here.
130
 
  QObexAuthDigestResponse( const QByteArray& );
131
 
  // Needed for list handling.
132
 
  QObexAuthDigestResponse();
133
 
  
134
 
  // Read access to the fields of the header data.
135
 
  QByteArray requestDigest() const;
136
 
  QByteArray nonce() const;
137
 
  bool hasNonce() const;
138
 
  QString userId() const;
139
 
  bool hasUserId() const;
140
 
 
141
 
  bool authenticate( const QByteArray& secret, const QByteArray& nonce ) const;
142
 
 
143
 
  /**
144
 
   */
145
 
  QString toString( int indent ) const;
146
 
};
147
 
 
148
 
#endif