@@ -87,8 +87,7 @@ func (p Pass) Add(creds *credentials.Credentials) error {
87
87
return errors .New ("missing credentials" )
88
88
}
89
89
90
- encoded := base64 .URLEncoding .EncodeToString ([]byte (creds .ServerURL ))
91
-
90
+ encoded := encodeServerURL (creds .ServerURL )
92
91
_ , err := p .runPass (creds .Secret , "insert" , "-f" , "-m" , path .Join (PASS_FOLDER , encoded , creds .Username ))
93
92
return err
94
93
}
@@ -99,7 +98,7 @@ func (p Pass) Delete(serverURL string) error {
99
98
return errors .New ("missing server url" )
100
99
}
101
100
102
- encoded := base64 . URLEncoding . EncodeToString ([] byte ( serverURL ) )
101
+ encoded := encodeServerURL ( serverURL )
103
102
_ , err := p .runPass ("" , "rm" , "-rf" , path .Join (PASS_FOLDER , encoded ))
104
103
return err
105
104
}
@@ -142,7 +141,7 @@ func (p Pass) Get(serverURL string) (string, string, error) {
142
141
return "" , "" , errors .New ("missing server url" )
143
142
}
144
143
145
- encoded := base64 . URLEncoding . EncodeToString ([] byte ( serverURL ) )
144
+ encoded := encodeServerURL ( serverURL )
146
145
147
146
if _ , err := os .Stat (path .Join (getPassDir (), PASS_FOLDER , encoded )); err != nil {
148
147
if os .IsNotExist (err ) {
@@ -180,7 +179,7 @@ func (p Pass) List() (map[string]string, error) {
180
179
continue
181
180
}
182
181
183
- serverURL , err := base64 . URLEncoding . DecodeString (server .Name ())
182
+ serverURL , err := decodeServerURL (server .Name ())
184
183
if err != nil {
185
184
return nil , err
186
185
}
@@ -194,8 +193,24 @@ func (p Pass) List() (map[string]string, error) {
194
193
continue
195
194
}
196
195
197
- resp [string ( serverURL ) ] = strings .TrimSuffix (usernames [0 ].Name (), ".gpg" )
196
+ resp [serverURL ] = strings .TrimSuffix (usernames [0 ].Name (), ".gpg" )
198
197
}
199
198
200
199
return resp , nil
201
200
}
201
+
202
+ // encodeServerURL returns the serverURL in base64-URL encoding to use
203
+ // as directory-name in pass storage.
204
+ func encodeServerURL (serverURL string ) string {
205
+ return base64 .URLEncoding .EncodeToString ([]byte (serverURL ))
206
+ }
207
+
208
+ // decodeServerURL decodes base64-URL encoded serverURL. ServerURLs are
209
+ // used in encoded format for directory-names in pass storage.
210
+ func decodeServerURL (encodedServerURL string ) (string , error ) {
211
+ serverURL , err := base64 .URLEncoding .DecodeString (encodedServerURL )
212
+ if err != nil {
213
+ return "" , err
214
+ }
215
+ return string (serverURL ), nil
216
+ }
0 commit comments