本文整理匯總了Golang中camlistore/org/pkg/blob.SHA1FromString函數的典型用法代碼示例。如果您正苦於以下問題:Golang SHA1FromString函數的具體用法?Golang SHA1FromString怎麽用?Golang SHA1FromString使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了SHA1FromString函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestSharingTransitiveSafety
// Issue 228: only follow transitive blobref links in known trusted schema fields.
func TestSharingTransitiveSafety(t *testing.T) {
st := newShareTester(t)
defer st.done()
content := "the secret"
contentRef := blob.SHA1FromString(content)
// User-injected blob, somehow.
evilClaim := fmt.Sprintf("Some payload containing the ref: %v", contentRef)
evilClaimRef := blob.SHA1FromString(evilClaim)
share := schema.NewShareRef(schema.ShareHaveRef, false).
SetShareTarget(evilClaimRef).
SetShareIsTransitive(true).
SetSigner(blob.SHA1FromString("irrelevant")).
SetRawStringField("camliSig", "alsounused")
shareRef := func() blob.Ref { return share.Blob().BlobRef() }
st.put(share.Blob())
st.putRaw(contentRef, content)
st.putRaw(evilClaimRef, evilClaim)
st.testGet(shareRef().String(), noError)
st.testGet(fmt.Sprintf("%s?via=%s", evilClaimRef, shareRef()), noError)
st.testGet(fmt.Sprintf("%s?via=%s,%s", contentRef, shareRef(), evilClaimRef), viaChainInvalidLink)
if !st.slept() {
t.Error("expected sleep after miss")
}
}
示例2: TestHandleGetViaSharing
func TestHandleGetViaSharing(t *testing.T) {
st := newShareTester(t)
defer st.done()
content := "monkey" // the secret
contentRef := blob.SHA1FromString(content)
link := fmt.Sprintf(`{"camliVersion": 1,
"camliType": "file",
"parts": [
{"blobRef": "%v", "size": %d}
]}`, contentRef, len(content))
linkRef := blob.SHA1FromString(link)
share := schema.NewShareRef(schema.ShareHaveRef, false).
SetShareTarget(linkRef).
SetSigner(blob.SHA1FromString("irrelevant")).
SetRawStringField("camliSig", "alsounused")
shareRef := func() blob.Ref { return share.Blob().BlobRef() }
t.Logf("Checking share blob doesn't yet exist...")
st.testGet(shareRef().String(), shareFetchFailed)
if !st.slept() {
t.Error("expected sleep after miss")
}
st.put(share.Blob())
t.Logf("Checking share blob now exists...")
st.testGet(shareRef().String(), noError)
t.Logf("Checking we can't get the content directly via the share...")
st.testGet(fmt.Sprintf("%s?via=%s", contentRef, shareRef()), shareTargetInvalid)
t.Logf("Checking we can't get the link (file) blob directly...")
st.putRaw(linkRef, link)
st.testGet(linkRef.String(), shareBlobInvalid)
t.Logf("Checking we can get the link (file) blob via the share...")
st.testGet(fmt.Sprintf("%s?via=%s", linkRef, shareRef()), noError)
t.Logf("Checking we can't get the content via the non-transitive share...")
st.testGet(fmt.Sprintf("%s?via=%s,%s", contentRef, shareRef(), linkRef), shareNotTransitive)
// TODO: new test?
share.SetShareIsTransitive(true)
st.put(share.Blob())
st.testGet(fmt.Sprintf("%s?via=%s,%s", linkRef, shareRef(), linkRef), viaChainInvalidLink)
st.putRaw(contentRef, content)
st.testGet(fmt.Sprintf("%s?via=%s,%s", contentRef, shareRef(), linkRef), noError)
// new test?
share.SetShareExpiration(time.Now().Add(-time.Duration(10) * time.Minute))
st.put(share.Blob())
st.testGet(fmt.Sprintf("%s?via=%s,%s", contentRef, shareRef(), linkRef), shareExpired)
share.SetShareExpiration(time.Now().Add(time.Duration(10) * time.Minute))
st.put(share.Blob())
st.testGet(fmt.Sprintf("%s?via=%s,%s", contentRef, shareRef(), linkRef), noError)
}
示例3: TestQueryFileConstraint_WholeRef
func TestQueryFileConstraint_WholeRef(t *testing.T) {
testQueryTypes(t, memIndexTypes, func(qt *queryTest) {
id := qt.id
fileRef, _ := id.UploadFile("some-stuff.txt", "hello", time.Unix(123, 0))
qt.t.Logf("fileRef = %q", fileRef)
p1 := id.NewPlannedPermanode("1")
id.SetAttribute(p1, "camliContent", fileRef.String())
fileRef2, _ := id.UploadFile("other-file", "hellooooo", time.Unix(456, 0))
qt.t.Logf("fileRef2 = %q", fileRef2)
p2 := id.NewPlannedPermanode("2")
id.SetAttribute(p2, "camliContent", fileRef2.String())
sq := &SearchQuery{
Constraint: &Constraint{
Permanode: &PermanodeConstraint{
Attr: "camliContent",
ValueInSet: &Constraint{
File: &FileConstraint{
WholeRef: blob.SHA1FromString("hello"),
},
},
},
},
}
qt.wantRes(sq, p1)
})
}
示例4: fileMapFromDuplicate
// fileMapFromDuplicate queries the server's search interface for an
// existing file blob for the file contents of wholeRef.
// If the server has it, it's validated, and then fileMap (which must
// already be partially populated) has its "parts" field populated,
// and then fileMap is uploaded (if necessary).
// If no file blob is found, a zero blob.Ref (and no error) is returned.
func (cl *Client) fileMapFromDuplicate(fileMap *schema.Builder, wholeRef blob.Ref) (blob.Ref, error) {
dupFileRef, err := cl.SearchExistingFileSchema(wholeRef)
if err != nil {
return blob.Ref{}, err
}
if !dupFileRef.Valid() {
// because SearchExistingFileSchema returns blob.Ref{}, nil when file is not found.
return blob.Ref{}, nil
}
dupMap, err := cl.FetchSchemaBlob(dupFileRef)
if err != nil {
return blob.Ref{}, fmt.Errorf("could not find existing file blob for wholeRef %q: %v", wholeRef, err)
}
fileMap.PopulateParts(dupMap.PartsSize(), dupMap.ByteParts())
json, err := fileMap.JSON()
if err != nil {
return blob.Ref{}, fmt.Errorf("could not write file map for wholeRef %q: %v", wholeRef, err)
}
bref := blob.SHA1FromString(json)
if bref == dupFileRef {
// Unchanged (same filename, modtime, JSON serialization, etc)
return dupFileRef, nil
}
sbr, err := cl.ReceiveBlob(bref, strings.NewReader(json))
if err != nil {
return blob.Ref{}, err
}
return sbr.Ref, nil
}
示例5: initSignerPublicKeyBlobref
func (c *Client) initSignerPublicKeyBlobref() {
if c.paramsOnly {
log.Print("client: paramsOnly set; cannot get public key from config or env vars.")
return
}
keyId := os.Getenv("CAMLI_KEYID")
if keyId == "" {
configOnce.Do(parseConfig)
keyId = config.Identity
if keyId == "" {
log.Fatalf("No 'identity' key in JSON configuration file %q; have you run \"camput init\"?", osutil.UserClientConfigPath())
}
}
keyRing := c.SecretRingFile()
if !fileExists(keyRing) {
log.Fatalf("Could not find keyId %q, because secret ring file %q does not exist.", keyId, keyRing)
}
entity, err := jsonsign.EntityFromSecring(keyId, keyRing)
if err != nil {
log.Fatalf("Couldn't find keyId %q in secret ring %v: %v", keyId, keyRing, err)
}
armored, err := jsonsign.ArmoredPublicKey(entity)
if err != nil {
log.Fatalf("Error serializing public key: %v", err)
}
c.signerPublicKeyRef = blob.SHA1FromString(armored)
c.publicKeyArmored = armored
}
示例6: TestSigner
func TestSigner(t *testing.T) {
if testing.Short() {
t.Skip("skipping in short mode")
}
ent, err := jsonsign.NewEntity()
if err != nil {
t.Fatal(err)
}
armorPub, err := jsonsign.ArmoredPublicKey(ent)
if err != nil {
t.Fatal(err)
}
pubRef := blob.SHA1FromString(armorPub)
sig, err := NewSigner(pubRef, strings.NewReader(armorPub), ent)
if err != nil {
t.Fatalf("NewSigner: %v", err)
}
pn, err := NewUnsignedPermanode().Sign(sig)
if err != nil {
t.Fatalf("NewPermanode: %v", err)
}
if !strings.Contains(pn, `,"camliSig":"`) {
t.Errorf("Permanode doesn't look signed: %v", pn)
}
}
示例7: uploadBytes
// uploadBytes populates bb (a builder of either type "bytes" or
// "file", which is a superset of "bytes"), sets it to the provided
// size, and populates with provided spans. The bytes or file schema
// blob is uploaded and its blobref is returned.
func uploadBytes(bs blobserver.StatReceiver, bb *Builder, size int64, s []span) *uploadBytesFuture {
future := newUploadBytesFuture()
parts := []BytesPart{}
addBytesParts(bs, &parts, s, future)
if err := bb.PopulateParts(size, parts); err != nil {
future.errc <- err
return future
}
// Hack until camlistore.org/issue/102 is fixed. If we happen to upload
// the "file" schema before any of its parts arrive, then the indexer
// can get confused. So wait on the parts before, and then upload
// the "file" blob afterwards.
if bb.Type() == "file" {
future.errc <- nil
_, err := future.Get() // may not be nil, if children parts failed
future = newUploadBytesFuture()
if err != nil {
future.errc <- err
return future
}
}
json := bb.Blob().JSON()
br := blob.SHA1FromString(json)
future.br = br
go func() {
_, err := uploadString(bs, br, json)
future.errc <- err
}()
return future
}
示例8: SetCamdevVars
func (e *Env) SetCamdevVars(altkey bool) {
e.Set("CAMLI_CONFIG_DIR", filepath.Join("config", "dev-client-dir"))
e.Set("CAMLI_AUTH", "userpass:camlistore:pass3179")
e.Set("CAMLI_DEV_KEYBLOBS", filepath.FromSlash("config/dev-client-dir/keyblobs"))
secring := defaultSecring
identity := defaultIdentity
if altkey {
secring = filepath.FromSlash("pkg/jsonsign/testdata/password-foo-secring.gpg")
identity = "C7C3E176"
println("**\n** Note: password is \"foo\"\n**\n")
} else {
if *flagSecretRing != "" {
secring = *flagSecretRing
}
if *flagIdentity != "" {
identity = *flagIdentity
}
}
entity, err := jsonsign.EntityFromSecring(identity, secring)
if err != nil {
panic(err)
}
armoredPublicKey, err := jsonsign.ArmoredPublicKey(entity)
if err != nil {
panic(err)
}
pubKeyRef := blob.SHA1FromString(armoredPublicKey)
e.Set("CAMLI_SECRET_RING", secring)
e.Set("CAMLI_KEYID", identity)
e.Set("CAMLI_PUBKEY_BLOBREF", pubKeyRef.String())
}
示例9: doKeyStuff
func doKeyStuff(b *testing.B) keyStuff {
camliRootPath, err := osutil.GoPackagePath("camlistore.org")
if err != nil {
b.Fatal("Package camlistore.org no found in $GOPATH or $GOPATH not defined")
}
secretRingFile := filepath.Join(camliRootPath, "pkg", "jsonsign", "testdata", "test-secring.gpg")
pubKey := `-----BEGIN PGP PUBLIC KEY BLOCK-----
xsBNBEzgoVsBCAC/56aEJ9BNIGV9FVP+WzenTAkg12k86YqlwJVAB/VwdMlyXxvi
bCT1RVRfnYxscs14LLfcMWF3zMucw16mLlJCBSLvbZ0jn4h+/8vK5WuAdjw2YzLs
WtBcjWn3lV6tb4RJz5gtD/o1w8VWxwAnAVIWZntKAWmkcChCRgdUeWso76+plxE5
aRYBJqdT1mctGqNEISd/WYPMgwnWXQsVi3x4z1dYu2tD9uO1dkAff12z1kyZQIBQ
rexKYRRRh9IKAayD4kgS0wdlULjBU98aeEaMz1ckuB46DX3lAYqmmTEL/Rl9cOI0
Enpn/oOOfYFa5h0AFndZd1blMvruXfdAobjVABEBAAE=
=28/7
-----END PGP PUBLIC KEY BLOCK-----`
return keyStuff{
secretRingFile: secretRingFile,
pubKey: pubKey,
pubKeyRef: blob.SHA1FromString(pubKey),
entityFetcher: &jsonsign.CachingEntityFetcher{
Fetcher: &jsonsign.FileEntityFetcher{File: secretRingFile},
},
}
}
示例10: writeFileMapOld
// This is the simple 1MB chunk version. The rolling checksum version is below.
func writeFileMapOld(bs blobserver.StatReceiver, file *Builder, r io.Reader) (blob.Ref, error) {
parts, size := []BytesPart{}, int64(0)
var buf bytes.Buffer
for {
buf.Reset()
n, err := io.Copy(&buf, io.LimitReader(r, maxBlobSize))
if err != nil {
return blob.Ref{}, err
}
if n == 0 {
break
}
hash := blob.NewHash()
io.Copy(hash, bytes.NewReader(buf.Bytes()))
br := blob.RefFromHash(hash)
hasBlob, err := serverHasBlob(bs, br)
if err != nil {
return blob.Ref{}, err
}
if !hasBlob {
sb, err := bs.ReceiveBlob(br, &buf)
if err != nil {
return blob.Ref{}, err
}
if want := (blob.SizedRef{br, uint32(n)}); sb != want {
return blob.Ref{}, fmt.Errorf("schema/filewriter: wrote %s, expect", sb, want)
}
}
size += n
parts = append(parts, BytesPart{
BlobRef: br,
Size: uint64(n),
Offset: 0, // into BlobRef to read from (not of dest)
})
}
err := file.PopulateParts(size, parts)
if err != nil {
return blob.Ref{}, err
}
json := file.Blob().JSON()
if err != nil {
return blob.Ref{}, err
}
br := blob.SHA1FromString(json)
sb, err := bs.ReceiveBlob(br, strings.NewReader(json))
if err != nil {
return blob.Ref{}, err
}
if expect := (blob.SizedRef{br, uint32(len(json))}); expect != sb {
return blob.Ref{}, fmt.Errorf("schema/filewriter: wrote %s bytes, got %s ack'd", expect, sb)
}
return br, nil
}
示例11: RunCommand
func (c *initCmd) RunCommand(args []string) error {
if len(args) > 0 {
return cmdmain.ErrUsage
}
if c.newKey && c.keyId != "" {
log.Fatal("--newkey and --gpgkey are mutually exclusive")
}
if c.userPass != "" {
cc, err := c.clientConfigFromServer()
if err != nil {
return err
}
return c.writeConfig(cc)
}
var err error
if c.newKey {
c.secretRing = osutil.DefaultSecretRingFile()
c.keyId, err = jsonsign.GenerateNewSecRing(c.secretRing)
if err != nil {
return err
}
} else {
if err := c.initSecretRing(); err != nil {
return err
}
if err := c.initKeyId(); err != nil {
return err
}
}
pubArmor, err := c.getPublicKeyArmored()
if err != nil {
return err
}
bref := blob.SHA1FromString(string(pubArmor))
log.Printf("Your Camlistore identity (your GPG public key's blobref) is: %s", bref.String())
if c.noconfig {
return nil
}
return c.writeConfig(&clientconfig.Config{
Servers: map[string]*clientconfig.Server{
"localhost": {
Server: "http://localhost:3179",
IsDefault: true,
Auth: "localhost",
},
},
Identity: c.keyId,
IgnoredFiles: []string{".DS_Store"},
})
}
示例12: getSignerPublicKeyBlobref
func getSignerPublicKeyBlobref() (signerRef blob.Ref, armored string, ok bool) {
configOnce.Do(parseConfig)
key := "keyId"
keyId, ok := config[key].(string)
if !ok {
log.Printf("No key %q in JSON configuration file %q; have you run \"camput init\"?", key, osutil.UserClientConfigPath())
return
}
keyRing, hasKeyRing := config["secretRing"].(string)
if !hasKeyRing {
if fn := osutil.IdentitySecretRing(); fileExists(fn) {
keyRing = fn
} else if fn := jsonsign.DefaultSecRingPath(); fileExists(fn) {
keyRing = fn
} else {
log.Printf("Couldn't find keyId %q; no 'secretRing' specified in config file, and no standard secret ring files exist.")
return
}
}
entity, err := jsonsign.EntityFromSecring(keyId, keyRing)
if err != nil {
log.Printf("Couldn't find keyId %q in secret ring: %v", keyId, err)
return
}
armored, err = jsonsign.ArmoredPublicKey(entity)
if err != nil {
log.Printf("Error serializing public key: %v", err)
return
}
// TODO(mpl): integrate with getSelfPubKeyDir if possible.
selfPubKeyDir, ok := config["selfPubKeyDir"].(string)
if !ok {
selfPubKeyDir = osutil.KeyBlobsDir()
log.Printf("No 'selfPubKeyDir' defined in %q, defaulting to %v", osutil.UserClientConfigPath(), selfPubKeyDir)
}
fi, err := os.Stat(selfPubKeyDir)
if err != nil || !fi.IsDir() {
log.Printf("selfPubKeyDir of %q doesn't exist or not a directory", selfPubKeyDir)
return
}
br := blob.SHA1FromString(armored)
pubFile := filepath.Join(selfPubKeyDir, br.String()+".camli")
fi, err = os.Stat(pubFile)
if err != nil {
err = ioutil.WriteFile(pubFile, []byte(armored), 0644)
if err != nil {
log.Printf("Error writing public key to %q: %v", pubFile, err)
return
}
}
return br, armored, true
}
示例13: searchOwner
// Error is errNoOwner if no identity configured
func (b *lowBuilder) searchOwner() (br blob.Ref, err error) {
if b.high.Identity == "" {
return br, errNoOwner
}
entity, err := jsonsign.EntityFromSecring(b.high.Identity, b.high.IdentitySecretRing)
if err != nil {
return br, err
}
armoredPublicKey, err := jsonsign.ArmoredPublicKey(entity)
if err != nil {
return br, err
}
return blob.SHA1FromString(armoredPublicKey), nil
}
示例14: newJSONSignFromConfig
func newJSONSignFromConfig(ld blobserver.Loader, conf jsonconfig.Obj) (http.Handler, error) {
var (
// either a short form ("26F5ABDA") or one the longer forms.
keyId = conf.RequiredString("keyId")
pubKeyDestPrefix = conf.OptionalString("publicKeyDest", "")
secretRing = conf.OptionalString("secretRing", "")
)
if err := conf.Validate(); err != nil {
return nil, err
}
h := &Handler{
secretRing: secretRing,
}
var err error
h.entity, err = jsonsign.EntityFromSecring(keyId, h.secretRingPath())
if err != nil {
return nil, err
}
h.pubKey, err = jsonsign.ArmoredPublicKey(h.entity)
ms := &memory.Storage{}
h.pubKeyBlobRef = blob.SHA1FromString(h.pubKey)
if _, err := ms.ReceiveBlob(h.pubKeyBlobRef, strings.NewReader(h.pubKey)); err != nil {
return nil, fmt.Errorf("could not store pub key blob: %v", err)
}
h.pubKeyFetcher = ms
if pubKeyDestPrefix != "" {
sto, err := ld.GetStorage(pubKeyDestPrefix)
if err != nil {
return nil, err
}
h.pubKeyDest = sto
}
h.pubKeyBlobRefServeSuffix = "camli/" + h.pubKeyBlobRef.String()
h.pubKeyHandler = &gethandler.Handler{
Fetcher: ms,
}
h.signer, err = schema.NewSigner(h.pubKeyBlobRef, strings.NewReader(h.pubKey), h.entity)
if err != nil {
return nil, err
}
return h, nil
}
示例15: setCamdevVarsFor
func setCamdevVarsFor(e *Env, altkey bool) {
var setenv func(string, string) error
if e != nil {
setenv = func(k, v string) error { e.Set(k, v); return nil }
} else {
setenv = os.Setenv
}
setenv("CAMLI_AUTH", "userpass:camlistore:pass3179")
// env values for clients. server will overwrite them anyway in its setEnvVars.
root, err := rootInTmpDir()
if err != nil {
log.Fatal(err)
}
setenv("CAMLI_CACHE_DIR", filepath.Join(root, "client", "cache"))
setenv("CAMLI_CONFIG_DIR", filepath.Join("config", "dev-client-dir"))
secring := defaultSecring
identity := defaultIdentity
if altkey {
secring = filepath.FromSlash("pkg/jsonsign/testdata/password-foo-secring.gpg")
identity = "C7C3E176"
println("**\n** Note: password is \"foo\"\n**\n")
} else {
if *flagSecretRing != "" {
secring = *flagSecretRing
}
if *flagIdentity != "" {
identity = *flagIdentity
}
}
entity, err := jsonsign.EntityFromSecring(identity, secring)
if err != nil {
panic(err)
}
armoredPublicKey, err := jsonsign.ArmoredPublicKey(entity)
if err != nil {
panic(err)
}
pubKeyRef := blob.SHA1FromString(armoredPublicKey)
setenv("CAMLI_SECRET_RING", secring)
setenv("CAMLI_KEYID", identity)
setenv("CAMLI_PUBKEY_BLOBREF", pubKeyRef.String())
setenv("CAMLI_KV_VERIFY", "true")
}