jsonsign: don't check for default secretring file unless we don't have an entity fetcher

Change-Id: I9ea58b09c5ad5465f64ce36d0cbc4edcc00c5d9d
This commit is contained in:
Brad Fitzpatrick 2011-10-12 22:59:47 -07:00
parent abf719be0b
commit da562c8bed
1 changed files with 6 additions and 10 deletions

View File

@ -249,21 +249,17 @@ func (sr *SignRequest) Sign() (signedJson string, err os.Error) {
trimmedJson = trimmedJson[0 : len(trimmedJson)-1]
// sign it
entityFetcher := sr.EntityFetcher
if entityFetcher == nil {
file := sr.secretRingPath()
if file == "" {
return "", os.NewError("jsonsign: no EntityFetcher, SecretKeyringPath, or secret-keyring flag provided")
}
secring, err := os.Open(sr.secretRingPath())
if err != nil {
return "", fmt.Errorf("jsonsign: failed to open secret ring file %q: %v", sr.secretRingPath(), err)
}
defer secring.Close()
entityFetcher := sr.EntityFetcher
if entityFetcher == nil {
file := sr.SecretKeyringPath
if file == "" {
file = flagSecretRing
}
if file == "" {
return "", os.NewError("jsonsign: no EntityFetcher, SecretKeyringPath, or secret-keyring flag provided")
}
secring.Close() // just opened to see if it's readable
entityFetcher = &FileEntityFetcher{File: file}
}
signer, err := entityFetcher.FetchEntity(pubk.KeyIdString())