@@ -8,9 +8,20 @@ import (
8
8
9
9
//go:generate go run ../build-tools/gen-gss-name-oids.go -o names_gen.go
10
10
11
- // GssNameType defines the name types in a mech-independent fashion,
12
- // as described in RFC 2743 § 4
13
- type GssNameType int
11
+ // GssNameType describes an available GSSAPI Name Type (NT) as described in
12
+ // RFC 2743 § 4.
13
+ type GssNameType interface {
14
+ // Oid returns the object identifier corresponding to the name type.
15
+ Oid () Oid
16
+ // OidString returns a printable version of the object identifier associated with the mechanism.
17
+ OidString () string
18
+ // String returns a printable version of the mechanism name.
19
+ String () string
20
+ }
21
+
22
+ // gssNameTypeImpl is an internal type that implements the GssNameType interface for the
23
+ // well-known name types. It supports well known name types.
24
+ type gssNameTypeImpl int
14
25
15
26
// GssName represents GSSAPI names (types INTERNAL NAME and MN) as described in RFC 2743 § 4.
16
27
// This interface includes support for name-related calls: GSS_Compare_name, GSS_Display_name,
@@ -29,7 +40,7 @@ type GssName interface {
29
40
// Returns:
30
41
// - equal: boolean value indicating whether the two names are equal
31
42
// - err: error if one occurred, otherwise nil
32
- Compare (other GssName ) (bool , error ) // RFC 2743 § 2.4.3
43
+ Compare (other GssName ) (equal bool , err error ) // RFC 2743 § 2.4.3
33
44
34
45
// Display implements GSS_Display_Name from RFC 2743 § 2.4.4.
35
46
// It returns a string representation of the name and its type.
@@ -38,13 +49,13 @@ type GssName interface {
38
49
// - disp: string representation of the name
39
50
// - nt: type of the name
40
51
// - err: error if one occurred, otherwise nil
41
- Display () (string , GssNameType , error ) // RFC 2743 § 2.4.4
52
+ Display () (disp string , nt GssNameType , err error ) // RFC 2743 § 2.4.4
42
53
43
54
// Release implements GSS_Release_Name from RFC 2743 § 2.4.6.
44
55
// It releases the name when it is no longer required.
45
56
//
46
57
// Returns:
47
- // - err: error if one occurred, otherwise nil
58
+ // - error if one occurred, otherwise nil
48
59
Release () error // RFC 2743 § 2.4.6
49
60
50
61
// InquireMechs implements GSS_Inquire_mechs_for_name from RFC 2743 § 2.4.13.
@@ -53,7 +64,7 @@ type GssName interface {
53
64
// Returns:
54
65
// - mechs: set of mechanisms that support the name
55
66
// - err: error if one occurred, otherwise nil
56
- InquireMechs () ([]GssMech , error ) // RFC 2743 § 2.4.13
67
+ InquireMechs () (mechs []GssMech , err error ) // RFC 2743 § 2.4.13
57
68
58
69
// Canonicalize implements GSS_Canonicalize_name from RFC 2743 § 2.4.14.
59
70
// It converts the name to a mechanism-specific form (MN).
@@ -64,7 +75,7 @@ type GssName interface {
64
75
// Returns:
65
76
// - name: the canonical GssName. This must be released using GssName.Release()
66
77
// - err: error if one occurred, otherwise nil
67
- Canonicalize (GssMech ) (GssName , error ) // RFC 2743 § 2.4.14
78
+ Canonicalize (mech GssMech ) (name GssName , err error ) // RFC 2743 § 2.4.14
68
79
69
80
// Export creates an exported byte representation of a mechanism name (MN) that is the result of
70
81
// a call to CanonicalizeName() or Provider.AcceptSecContext().
@@ -76,23 +87,23 @@ type GssName interface {
76
87
// Returns:
77
88
// - exp: the exported name representation
78
89
// - err: error if one occurred, otherwise nil
79
- Export () ([]byte , error ) // RFC 2743 § 2.4.15
90
+ Export () (exp []byte , err error ) // RFC 2743 § 2.4.15
80
91
81
92
// Duplicate implements GSS_Duplicate_name from RFC 2743 § 2.4.16.
82
93
// It creates a copy of the name that remains valid even if the source name is released.
83
94
//
84
95
// Returns:
85
96
// - name: the duplicated name. This must be released using GssName.Release()
86
97
// - err: error if one occurred, otherwise nil
87
- Duplicate () (GssName , error ) // RFC 2743 § 2.4.16
98
+ Duplicate () (name GssName , err error ) // RFC 2743 § 2.4.16
88
99
}
89
100
90
101
// NOTE: if the order here changes also change
91
102
// gen-gss-name-oids.go!
92
103
93
104
const (
94
105
// Host-based name form (RFC 2743 § 4.1), "service@host" or just "service"
95
- GSS_NT_HOSTBASED_SERVICE GssNameType = iota
106
+ GSS_NT_HOSTBASED_SERVICE gssNameTypeImpl = iota
96
107
97
108
// User name form (RFC 2743 § 4.2), "username" : named local user
98
109
GSS_NT_USER_NAME
@@ -136,48 +147,56 @@ const (
136
147
_GSS_NAME_TYPE_LAST
137
148
)
138
149
139
- func (nt GssNameType ) Oid () Oid {
150
+ func (nt gssNameTypeImpl ) Oid () Oid {
140
151
if nt >= _GSS_NAME_TYPE_LAST {
141
152
panic (ErrBadNameType )
142
153
}
143
154
144
155
return nameTypes [nt ].oid
145
156
}
146
157
147
- func (nt GssNameType ) OidString () string {
158
+ func (nt gssNameTypeImpl ) OidString () string {
148
159
if nt >= _GSS_NAME_TYPE_LAST {
149
160
panic (ErrBadNameType )
150
161
}
151
162
152
163
return nameTypes [nt ].oidString
153
164
}
154
165
155
- func (nt GssNameType ) String () string {
166
+ func (nt gssNameTypeImpl ) String () string {
156
167
if nt >= _GSS_NAME_TYPE_LAST {
157
168
panic (ErrBadNameType )
158
169
}
159
170
160
171
return nameTypes [nt ].name
161
172
}
162
173
163
- // NameFromOid returns the name type associated with an OID, or an error if the OID is unknown.
174
+ // NameTypeFromOid returns the name type associated with an OID.
175
+ //
176
+ // The standard implementation offers this function for use with the gssNameTypeImpl
177
+ // internal type for a standard set of well known name types.
178
+ //
179
+ // If a provider needs to support a different name type, it can be added to gssNameTypeImpl via a pull
180
+ // request to the go-gssapi repository. Alternatively, a new implementation of GssNameType can be
181
+ // created for use by that GSSAPI implementation. Depending on the requirements, a replacement for
182
+ // NameTypeFromOid may also need to be provided by the provider.
164
183
// This function is provided to map a name OID to a name type.
165
184
//
166
185
// Parameters:
167
186
// - oid: the object identifier to look up
168
187
//
169
188
// Returns:
170
- // - GssNameType : the corresponding name type
189
+ // - gssNameTypeImpl : the corresponding name type
171
190
// - error: ErrBadNameType if the OID is not recognized
172
- func NameFromOid (oid Oid ) (GssNameType , error ) {
191
+ func NameTypeFromOid (oid Oid ) (gssNameTypeImpl , error ) {
173
192
for i , nt := range nameTypes {
174
193
if slices .Equal (nt .oid , oid ) {
175
- return GssNameType (i ), nil
194
+ return gssNameTypeImpl (i ), nil
176
195
}
177
196
178
197
for _ , alt := range nt .altOids {
179
198
if slices .Equal (alt , oid ) {
180
- return GssNameType (i ), nil
199
+ return gssNameTypeImpl (i ), nil
181
200
}
182
201
}
183
202
}
0 commit comments