// SignWriterMetadataInternally implements the MutableRootMetadata interface for RootMetadataV2.
17008
func (md *RootMetadataV2) SignWriterMetadataInternally(
	ctx context.Context, codec kbfscodec.Codec,
	signer kbfscrypto.Signer) error {
	buf, err := codec.Encode(md.WriterMetadataV2)
	if err != nil {
		return err
	}

	sigInfo, err := signer.Sign(ctx, buf)
	if err != nil {
		return err
	}
	md.WriterMetadataSigInfo = sigInfo
	return nil
}
629847
func (api *SignerAPI) SignData(ctx context.Context, contentType string, addr common.MixedcaseAddress, data interface{}) (hexutil.Bytes, error) {
	var req, transformV, err = api.determineSignatureFormat(ctx, contentType, addr, data)
	if err != nil {
		return nil, err
	}

	signature, err := api.sign(addr, req, transformV)
	if err != nil {
		api.UI.ShowError(err.Error())
		return nil, err
	}
	return signature, nil
}
98939
func WriteIndexMetadata(path string, meta *IndexMetadata) error {
	return writeJSON(indexMetadataPath(path), meta)
}
812952
func (rmds *RootMetadataSigned) MakeFinalCopy(
	codec kbfscodec.Codec, finalizedInfo *tlf.HandleExtension) (*RootMetadataSigned, error) {
	if finalizedInfo.Type != tlf.HandleExtensionFinalized {
		return nil, fmt.Errorf(
			"Extension %s does not have finalized type",
			finalizedInfo)
	}
	if rmds.MD.IsFinal() {
		return nil, MetadataIsFinalError{}
	}
	newMd, err := rmds.MD.DeepCopy(codec)
	if err != nil {
		return nil, err
	}
	// Set the final flag.
	newMd.SetFinalBit()
	// Set the copied bit, so that clients don't take the ops and byte
	// counts in it seriously.
	newMd.SetWriterMetadataCopiedBit()
	// Increment revision but keep the PrevRoot --
	// We want the client to be able to verify the signature by masking out the final
	// bit, decrementing the revision, and nulling out the finalized extension info.
	// This way it can easily tell a server didn't modify anything unexpected when
	// creating the final metadata block. Note that PrevRoot isn't being updated. This
	// is to make verification easier for the client as otherwise it'd need to request
	// the head revision - 1.
	newMd.SetRevision(rmds.MD.RevisionNumber() + 1)
	newMd.SetFinalizedInfo(finalizedInfo)
	return makeRootMetadataSigned(
		rmds.SigInfo.DeepCopy(), rmds.WriterSigInfo.DeepCopy(),
		newMd)
}
942143
func (d *DotGit) ConfigWriter() (billy.File, error) {
	return d.fs.Create(configPath)
}
954046
func (writer *Writer) WriteHeader() error {
	if !writer.Resource.Config.WithoutHeader {
		var results []string
		for _, meta := range writer.metas {
			results = append(results, meta.Header)
		}
		writer.Writer.Write(results)
	}
	return nil
}
940034
func (v *DeviceMapperVolume) WriteMetadata(label, name string) (io.WriteCloser, error) {
	filePath := filepath.Join(v.driver.MetadataDir(), v.rawSnapshotLabel(label), name)
	if err := os.MkdirAll(filepath.Dir(filePath), 0755); err != nil && !os.IsExist(err) {
		glog.Errorf("Could not create path for file %s: %s", name, err)
		return nil, err
	}
	return os.Create(filePath)
}
952589
func (c *Client) SignHandler() (string, error) {
	if err := c.condDiscovery(); err != nil {
		return "", err
	}
	if c.signHandler == "" {
		return "", ErrNoSigning
	}
	return c.signHandler, nil
}
541025
func (s *Secret) TokenMetadata() (map[string]string, error) {
	if s == nil {
		return nil, nil
	}

	if s.Auth != nil && len(s.Auth.Metadata) > 0 {
		return s.Auth.Metadata, nil
	}

	if s.Data == nil || (s.Data["metadata"] == nil && s.Data["meta"] == nil) {
		return nil, nil
	}

	data, ok := s.Data["metadata"].(map[string]interface{})
	if !ok {
		data, ok = s.Data["meta"].(map[string]interface{})
		if !ok {
			return nil, fmt.Errorf("unable to convert metadata field to expected format")
		}
	}

	metadata := make(map[string]string, len(data))
	for k, v := range data {
		typed, ok := v.(string)
		if !ok {
			return nil, fmt.Errorf("unable to convert metadata value %v to string", v)
		}
		metadata[k] = typed
	}

	return metadata, nil
}
748223
func (api *ExternalSigner) SignData(account accounts.Account, mimeType string, data []byte) ([]byte, error) {
	var res hexutil.Bytes
	var signAddress = common.NewMixedcaseAddress(account.Address)
	if err := api.client.Call(&res, "account_signData",
		mimeType,
		&signAddress, // Need to use the pointer here, because of how MarshalJSON is defined
		hexutil.Encode(data)); err != nil {
		return nil, err
	}
	// If V is on 27/28-form, convert to to 0/1 for Clique
	if mimeType == accounts.MimetypeClique && (res[64] == 27 || res[64] == 28) {
		res[64] -= 27 // Transform V from 27/28 to 0/1 for Clique use
	}
	return res, nil
}
776847
func (c *consulClientImpl) writeRetryFunc(f writeFunc) (*api.WriteMeta, error) {
	var err error
	var meta *api.WriteMeta
	retry := false
	c.runWithRetry(func() bool {
		conn := c.conn
		meta, err = f(conn)
		retry, err = c.reconnectIfConnectionError(conn, err)
		return retry
	})
	return meta, err
}
643479
func (h *authHeaderWriterTo) WriteTo(w io.Writer) (n int64, err error) {

	var (
		signedContent bytes.Buffer
		bytesWritten  int64
	)

	// Timestamp
	ts := jwt.TimeFunc().UTC().Unix()
	if err = binary.Write(&signedContent, byteOrder, timestamp(ts)); err != nil {
		return 0, err
	}

	// Token len
	tokenLen := len(h.token)
	// Check to see if it overflows uint16
	if int(tokenLength(tokenLen)) != tokenLen {
		return 0, ErrBadToken
	}

	// Token
	if err = binary.Write(&signedContent, byteOrder, h.token); err != nil {
		return 0, err
	}

	// Payload len
	payloadLen := len(h.payload)
	// Check to see if it overflows uint16
	if int(payloadLength(payloadLen)) != payloadLen {
		return 0, ErrPayloadTooLarge
	}
	if err = binary.Write(&signedContent, byteOrder, payloadLength(payloadLen)); err != nil {
		return 0, err
	}

	// Payload
	if err = binary.Write(&signedContent, byteOrder, h.payload); err != nil {
		return 0, err
	}

	// Sign the contents of the buffer
	sig, err := h.signer.Sign(signedContent.Bytes())
	if err != nil {
		return 0, err
	}

	// Write the magic number
	err = binary.Write(w, byteOrder, MagicNumber)
	if err != nil {
		return n, err
	}
	n += int64(binary.Size(MagicNumber))

	// Write the protocol version
	err = binary.Write(w, byteOrder, ProtocolVersion)
	if err != nil {
		return n, err
	}
	n += int64(binary.Size(ProtocolVersion))

	// Write the length of everything left except the payload len and payload
	allLen := uint32(tokenLen + 8)
	err = binary.Write(w, byteOrder, allLen)
	if err != nil {
		return n, err
	}

	// Write the signature
	err = binary.Write(w, byteOrder, sig)
	if err != nil {
		return n, err
	}
	n += int64(binary.Size(sig))

	// Write the buffer contents (timestamp, token, payloadlen, payload)
	bytesWritten, err = signedContent.WriteTo(w)
	if err != nil {
		return n, err
	}
	n += bytesWritten

	return n, nil
}
560888
func (info *HostCertificateInfo) Write(w io.Writer) error {
	tw := tabwriter.NewWriter(w, 2, 0, 2, ' ', 0)

	s := func(val string) string {
		if val != "" {
			return val
		}
		return "<Not Part Of Certificate>"
	}

	ss := func(val []string) string {
		return s(strings.Join(val, ","))
	}

	name := func(n *pkix.Name) {
		fmt.Fprintf(tw, "  Common Name (CN):\t%s\n", s(n.CommonName))
		fmt.Fprintf(tw, "  Organization (O):\t%s\n", ss(n.Organization))
		fmt.Fprintf(tw, "  Organizational Unit (OU):\t%s\n", ss(n.OrganizationalUnit))
	}

	status := info.Status
	if info.Err != nil {
		status = fmt.Sprintf("ERROR %s", info.Err)
	}
	fmt.Fprintf(tw, "Certificate Status:\t%s\n", status)

	fmt.Fprintln(tw, "Issued To:\t")
	name(info.SubjectName())

	fmt.Fprintln(tw, "Issued By:\t")
	name(info.IssuerName())

	fmt.Fprintln(tw, "Validity Period:\t")
	fmt.Fprintf(tw, "  Issued On:\t%s\n", info.NotBefore)
	fmt.Fprintf(tw, "  Expires On:\t%s\n", info.NotAfter)

	if info.ThumbprintSHA1 != "" {
		fmt.Fprintln(tw, "Thumbprints:\t")
		if info.ThumbprintSHA256 != "" {
			fmt.Fprintf(tw, "  SHA-256 Thumbprint:\t%s\n", info.ThumbprintSHA256)
		}
		fmt.Fprintf(tw, "  SHA-1 Thumbprint:\t%s\n", info.ThumbprintSHA1)
	}

	return tw.Flush()
}
512684
func makeRootMetadataSigned(rmds *kbfsmd.RootMetadataSigned,
	untrustedServerTimestamp time.Time) *RootMetadataSigned {
	return &RootMetadataSigned{
		RootMetadataSigned:       *rmds,
		untrustedServerTimestamp: untrustedServerTimestamp,
	}
}
1072938
func MakeImmutableRootMetadata(
	rmd *RootMetadata, writerVerifyingKey kbfscrypto.VerifyingKey,
	mdID kbfsmd.ID, localTimestamp time.Time,
	putToServer bool) ImmutableRootMetadata {
	if writerVerifyingKey == (kbfscrypto.VerifyingKey{}) {
		panic("zero writerVerifyingKey passed to MakeImmutableRootMetadata")
	}
	if mdID == (kbfsmd.ID{}) {
		panic("zero mdID passed to MakeImmutableRootMetadata")
	}
	if localTimestamp.IsZero() {
		panic("zero localTimestamp passed to MakeImmutableRootMetadata")
	}
	if bareMDV2, ok := rmd.bareMd.(*kbfsmd.RootMetadataV2); ok {
		writerSig := bareMDV2.WriterMetadataSigInfo
		if writerSig.IsNil() {
			panic("MDV2 with nil writer signature")
		}
		if writerSig.VerifyingKey != writerVerifyingKey {
			panic(fmt.Sprintf("key mismatch: sig has %s, expected %s",
				writerSig.VerifyingKey, writerVerifyingKey))
		}
	}
	return ImmutableRootMetadata{
		rmd.ReadOnly(), mdID, writerVerifyingKey, localTimestamp, putToServer}
}
402205
func (md *RootMetadata) GetSerializedWriterMetadata(
	codec kbfscodec.Codec) ([]byte, error) {
	return md.bareMd.GetSerializedWriterMetadata(codec)
}
1095496
func WriteCertAndKey(pkiPath string, name string, cert *x509.Certificate, key crypto.Signer) error {
	if err := WriteKey(pkiPath, name, key); err != nil {
		return errors.Wrap(err, "couldn't write key")
	}

	return WriteCert(pkiPath, name, cert)
}