예제 #1
0
func (g *GPGKey) SignToString(msg []byte) (sig string, id keybase1.SigID, err error) {
	g.G().Log.Debug("+ GPGKey Signing %s", string(msg))
	defer func() {
		g.G().Log.Debug("- GPGKey Signing -> %s", err)
	}()

	if g.ct == keybase1.ClientType_CLI {
		g.G().Log.Debug("| GPGKey reverse delegate to CLI")
		sig, err = g.ui.Sign(context.TODO(), keybase1.SignArg{Fingerprint: (*g.fp)[:], Msg: msg})
	} else {
		g.G().Log.Debug("| GPGKey sign in-process; let's hope for the best!")
		sig, err = g.G().GetGpgClient().Sign(*g.fp, msg)
	}

	if err != nil {
		return sig, id, err
	}

	// compute sig id:
	h := sha256.New()
	h.Write(msg)
	id, err = keybase1.SigIDFromSlice(h.Sum(nil))
	if err != nil {
		return sig, id, err
	}

	return sig, id, nil
}
예제 #2
0
파일: sign.go 프로젝트: mark-adams/client
// SimpleSign signs the given data stream, outputs an armored string which is
// the attached signature of the input data
func SimpleSign(payload []byte, key PGPKeyBundle) (out string, id keybase1.SigID, err error) {
	var outb bytes.Buffer
	var in io.WriteCloser
	var h HashSummer
	if in, h, err = ArmoredAttachedSign(NopWriteCloser{&outb}, *key.Entity, nil, nil); err != nil {
		return
	}
	if _, err = in.Write(payload); err != nil {
		return
	}
	if err = in.Close(); err != nil {
		return
	}
	out = outb.String()
	if id, err = keybase1.SigIDFromSlice(h()); err != nil {
		return
	}
	return
}