@@ -94,7 +94,8 @@ func (h Osxkeychain) Get(serverURL string) (string, string, error) {
9494 return user , pass , nil
9595}
9696
97- func (h Osxkeychain ) List () ([]string , []string , error ) {
97+ // List returns the stored URLs and corresponding usernames.
98+ func (h Osxkeychain ) List () (map [string ]string , error ) {
9899 var pathsC * * C.char
99100 defer C .free (unsafe .Pointer (pathsC ))
100101 var acctsC * * C.char
@@ -104,29 +105,25 @@ func (h Osxkeychain) List() ([]string, []string, error) {
104105 if errMsg != nil {
105106 defer C .free (unsafe .Pointer (errMsg ))
106107 goMsg := C .GoString (errMsg )
107- return nil , nil , errors .New (goMsg )
108+ return nil , errors .New (goMsg )
108109 }
110+
111+ defer C .freeListData (& pathsC , listLenC )
112+ defer C .freeListData (& acctsC , listLenC )
113+
109114 var listLen int
110115 listLen = int (listLenC )
111116 pathTmp := (* [1 << 30 ]* C.char )(unsafe .Pointer (pathsC ))[:listLen :listLen ]
112117 acctTmp := (* [1 << 30 ]* C.char )(unsafe .Pointer (acctsC ))[:listLen :listLen ]
113118 //taking the array of c strings into go while ignoring all the stuff irrelevant to credentials-helper
114- paths := make ([]string , listLen )
115- accts := make ([]string , listLen )
116- at := 0
119+ resp := make (map [string ]string )
117120 for i := 0 ; i < listLen ; i ++ {
118121 if C .GoString (pathTmp [i ]) == "0" {
119122 continue
120123 }
121- paths [at ] = C .GoString (pathTmp [i ])
122- accts [at ] = C .GoString (acctTmp [i ])
123- at = at + 1
124+ resp [C .GoString (pathTmp [i ])] = C .GoString (acctTmp [i ])
124125 }
125- paths = paths [:at ]
126- accts = accts [:at ]
127- C .freeListData (& pathsC , listLenC )
128- C .freeListData (& acctsC , listLenC )
129- return paths , accts , nil
126+ return resp , nil
130127}
131128
132129func splitServer (serverURL string ) (* C.struct_Server , error ) {
0 commit comments