@@ -98,13 +98,50 @@ var (
98
98
ErrRequiresUI = errors .New ("provider requries UI to operate" )
99
99
)
100
100
101
- // Error codes for Windows APIs - implements the error interface
101
+ // Error codes for Windows APIs - implements the error interface.
102
+ // Error codes are maintained on a per-thread basis. In order to
103
+ // get the last error code, C.GetLastError needs to be called (called
104
+ // within the checkError() function). Some Windows APIs only return
105
+ // BOOLs indicating success or failure, and for more detailed error
106
+ // information, error codes are used.
102
107
type errCode uint64
103
108
104
- // Security status for Windows APIs - implements the error interface
105
- // Go representation of the C SECURITY_STATUS
109
+ // Implements the error interface for errCode and returns a string
110
+ // version of the errCode
111
+ func (c errCode ) Error () string {
112
+ var cMsg C.LPSTR
113
+ ret := C .FormatMessage (
114
+ C .FORMAT_MESSAGE_ALLOCATE_BUFFER |
115
+ C .FORMAT_MESSAGE_FROM_SYSTEM |
116
+ C .FORMAT_MESSAGE_IGNORE_INSERTS ,
117
+ nil ,
118
+ C .DWORD (c ),
119
+ C .ulong (C .MAKE_LANG_ID (C .LANG_NEUTRAL , C .SUBLANG_DEFAULT )),
120
+ cMsg ,
121
+ 0 , nil )
122
+ if ret == 0 {
123
+ return fmt .Sprintf ("Error %X" , int (c ))
124
+ }
125
+
126
+ if cMsg == nil {
127
+ return fmt .Sprintf ("Error %X" , int (c ))
128
+ }
129
+
130
+ goMsg := C .GoString (cMsg )
131
+
132
+ return fmt .Sprintf ("Error: %X %s" , int (c ), goMsg )
133
+ }
134
+
135
+ // Security status for Windows APIs - implements the error interface.
136
+ // Some Windows API calls return this type directly.
137
+ // Go representation of the C SECURITY_STATUS.
106
138
type securityStatus uint64
107
139
140
+ // Implements the error interface
141
+ func (secStatus securityStatus ) Error () string {
142
+ return fmt .Sprintf ("SECURITY_STATUS %d" , int (secStatus ))
143
+ }
144
+
108
145
// Gets the certificates that match the given CertIdentifier within the user's "MY" certificate store.
109
146
// If there is only a single matching certificate, then its chain will be returned too
110
147
func GetMatchingCertsAndChain (certIdentifier CertIdentifier ) (store windows.Handle , certCtx * windows.CertContext , certChain []* x509.Certificate , certContainers []CertificateContainer , err error ) {
@@ -596,32 +633,6 @@ func checkError(msg string) error {
596
633
return nil
597
634
}
598
635
599
- // Implements the error interface for errCode and returns a string
600
- // version of the errCode
601
- func (c errCode ) Error () string {
602
- var cMsg C.LPSTR
603
- ret := C .FormatMessage (
604
- C .FORMAT_MESSAGE_ALLOCATE_BUFFER |
605
- C .FORMAT_MESSAGE_FROM_SYSTEM |
606
- C .FORMAT_MESSAGE_IGNORE_INSERTS ,
607
- nil ,
608
- C .DWORD (c ),
609
- C .ulong (C .MAKE_LANG_ID (C .LANG_NEUTRAL , C .SUBLANG_DEFAULT )),
610
- cMsg ,
611
- 0 , nil )
612
- if ret == 0 {
613
- return fmt .Sprintf ("Error %X" , int (c ))
614
- }
615
-
616
- if cMsg == nil {
617
- return fmt .Sprintf ("Error %X" , int (c ))
618
- }
619
-
620
- goMsg := C .GoString (cMsg )
621
-
622
- return fmt .Sprintf ("Error: %X %s" , int (c ), goMsg )
623
- }
624
-
625
636
// Converts a SECURITY_STATUS into a securityStatus
626
637
func checkStatus (s C.SECURITY_STATUS ) error {
627
638
secStatus := securityStatus (s )
@@ -640,8 +651,3 @@ func checkStatus(s C.SECURITY_STATUS) error {
640
651
641
652
return secStatus
642
653
}
643
-
644
- // Implements the error interface
645
- func (secStatus securityStatus ) Error () string {
646
- return fmt .Sprintf ("SECURITY_STATUS %d" , int (secStatus ))
647
- }
0 commit comments