mirror of https://github.com/ethereum/go-ethereum
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.7 KiB
62 lines
1.7 KiB
9 years ago
|
// Copyright 2015 The go-ethereum Authors
|
||
9 years ago
|
// This file is part of the go-ethereum library.
|
||
10 years ago
|
//
|
||
9 years ago
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||
10 years ago
|
// it under the terms of the GNU Lesser General Public License as published by
|
||
|
// the Free Software Foundation, either version 3 of the License, or
|
||
|
// (at your option) any later version.
|
||
|
//
|
||
9 years ago
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||
10 years ago
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
9 years ago
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
10 years ago
|
// GNU Lesser General Public License for more details.
|
||
|
//
|
||
|
// You should have received a copy of the GNU Lesser General Public License
|
||
9 years ago
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||
10 years ago
|
|
||
8 years ago
|
package keystore
|
||
10 years ago
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
"fmt"
|
||
|
"os"
|
||
10 years ago
|
"path/filepath"
|
||
10 years ago
|
|
||
|
"github.com/ethereum/go-ethereum/common"
|
||
10 years ago
|
)
|
||
|
|
||
10 years ago
|
type keyStorePlain struct {
|
||
10 years ago
|
keysDirPath string
|
||
|
}
|
||
|
|
||
9 years ago
|
func (ks keyStorePlain) GetKey(addr common.Address, filename, auth string) (*Key, error) {
|
||
|
fd, err := os.Open(filename)
|
||
10 years ago
|
if err != nil {
|
||
9 years ago
|
return nil, err
|
||
|
}
|
||
9 years ago
|
defer fd.Close()
|
||
9 years ago
|
key := new(Key)
|
||
9 years ago
|
if err := json.NewDecoder(fd).Decode(key); err != nil {
|
||
9 years ago
|
return nil, err
|
||
10 years ago
|
}
|
||
9 years ago
|
if key.Address != addr {
|
||
|
return nil, fmt.Errorf("key content mismatch: have address %x, want %x", key.Address, addr)
|
||
10 years ago
|
}
|
||
9 years ago
|
return key, nil
|
||
10 years ago
|
}
|
||
|
|
||
9 years ago
|
func (ks keyStorePlain) StoreKey(filename string, key *Key, auth string) error {
|
||
|
content, err := json.Marshal(key)
|
||
10 years ago
|
if err != nil {
|
||
10 years ago
|
return err
|
||
10 years ago
|
}
|
||
9 years ago
|
return writeKeyFile(filename, content)
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
9 years ago
|
func (ks keyStorePlain) JoinPath(filename string) string {
|
||
|
if filepath.IsAbs(filename) {
|
||
|
return filename
|
||
10 years ago
|
}
|
||
7 years ago
|
return filepath.Join(ks.keysDirPath, filename)
|
||
10 years ago
|
}
|