@@ -87,8 +87,7 @@ func (p Pass) Add(creds *credentials.Credentials) error {
8787 return errors .New ("missing credentials" )
8888 }
8989
90- encoded := base64 .URLEncoding .EncodeToString ([]byte (creds .ServerURL ))
91-
90+ encoded := encodeServerURL (creds .ServerURL )
9291 _ , err := p .runPass (creds .Secret , "insert" , "-f" , "-m" , path .Join (PASS_FOLDER , encoded , creds .Username ))
9392 return err
9493}
@@ -99,7 +98,7 @@ func (p Pass) Delete(serverURL string) error {
9998 return errors .New ("missing server url" )
10099 }
101100
102- encoded := base64 . URLEncoding . EncodeToString ([] byte ( serverURL ) )
101+ encoded := encodeServerURL ( serverURL )
103102 _ , err := p .runPass ("" , "rm" , "-rf" , path .Join (PASS_FOLDER , encoded ))
104103 return err
105104}
@@ -142,7 +141,7 @@ func (p Pass) Get(serverURL string) (string, string, error) {
142141 return "" , "" , errors .New ("missing server url" )
143142 }
144143
145- encoded := base64 . URLEncoding . EncodeToString ([] byte ( serverURL ) )
144+ encoded := encodeServerURL ( serverURL )
146145
147146 if _ , err := os .Stat (path .Join (getPassDir (), PASS_FOLDER , encoded )); err != nil {
148147 if os .IsNotExist (err ) {
@@ -180,7 +179,7 @@ func (p Pass) List() (map[string]string, error) {
180179 continue
181180 }
182181
183- serverURL , err := base64 . URLEncoding . DecodeString (server .Name ())
182+ serverURL , err := decodeServerURL (server .Name ())
184183 if err != nil {
185184 return nil , err
186185 }
@@ -194,8 +193,24 @@ func (p Pass) List() (map[string]string, error) {
194193 continue
195194 }
196195
197- resp [string ( serverURL ) ] = strings .TrimSuffix (usernames [0 ].Name (), ".gpg" )
196+ resp [serverURL ] = strings .TrimSuffix (usernames [0 ].Name (), ".gpg" )
198197 }
199198
200199 return resp , nil
201200}
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