allow fetcher or streaming fetcher in jsonsign signing

This commit is contained in:
Brad Fitzpatrick 2011-05-03 17:34:16 -07:00
parent 8658894096
commit 1ba5fd168a
1 changed files with 13 additions and 3 deletions

View File

@ -17,16 +17,18 @@ limitations under the License.
package jsonsign package jsonsign
import ( import (
"camli/blobref"
"exec" "exec"
"flag" "flag"
"fmt" "fmt"
"io"
"io/ioutil" "io/ioutil"
"json" "json"
"log" "log"
"os" "os"
"strings" "strings"
"unicode" "unicode"
"camli/blobref"
) )
var gpgPath *string = flag.String("gpg-path", "/usr/bin/gpg", "Path to the gpg binary.") var gpgPath *string = flag.String("gpg-path", "/usr/bin/gpg", "Path to the gpg binary.")
@ -40,7 +42,7 @@ var flagSecretRing *string = flag.String("secret-keyring", "./test/test-secring.
type SignRequest struct { type SignRequest struct {
UnsignedJson string UnsignedJson string
Fetcher blobref.Fetcher Fetcher interface{} // blobref.Fetcher or blobref.StreamingFetcher
UseAgent bool UseAgent bool
// In server-mode, don't use any default (user) keys // In server-mode, don't use any default (user) keys
@ -92,7 +94,15 @@ func (sr *SignRequest) Sign() (signedJson string, err os.Error) {
return inputfail("json \"camliSigner\" key is malformed or unsupported") return inputfail("json \"camliSigner\" key is malformed or unsupported")
} }
pubkeyReader, _, err := sr.Fetcher.Fetch(signerBlob) var pubkeyReader io.ReadCloser
switch fetcher := sr.Fetcher.(type) {
case blobref.Fetcher:
pubkeyReader, _, err = fetcher.Fetch(signerBlob)
case blobref.StreamingFetcher:
pubkeyReader, _, err = fetcher.FetchStreaming(signerBlob)
default:
panic(fmt.Sprintf("jsonsign: bogus SignRequest.Fetcher of type %T", sr.Fetcher))
}
if err != nil { if err != nil {
// TODO: not really either an inputfail or an execfail.. but going // TODO: not really either an inputfail or an execfail.. but going
// with exec for now. // with exec for now.