LogMessageForSerializedIdentity returns a string with serialized identity information, or a string indicating why the serialized identity information cannot be returned. Any errors are intentionally returned in the return strings so that the function can be used in single-line log messages with mini
(serializedIdentity []byte)
| 90 | // or a string indicating why the serialized identity information cannot be returned. |
| 91 | // Any errors are intentionally returned in the return strings so that the function can be used in single-line log messages with minimal clutter. |
| 92 | func LogMessageForSerializedIdentity(serializedIdentity []byte) string { |
| 93 | id := &msp.SerializedIdentity{} |
| 94 | err := proto.Unmarshal(serializedIdentity, id) |
| 95 | if err != nil { |
| 96 | return fmt.Sprintf("Could not unmarshal serialized identity: %s", err) |
| 97 | } |
| 98 | pemBlock, _ := pem.Decode(id.IdBytes) |
| 99 | if pemBlock == nil { |
| 100 | // not all identities are certificates so simply log the serialized |
| 101 | // identity bytes |
| 102 | return fmt.Sprintf("serialized-identity=%x", serializedIdentity) |
| 103 | } |
| 104 | cert, err := x509.ParseCertificate(pemBlock.Bytes) |
| 105 | if err != nil { |
| 106 | return fmt.Sprintf("Could not parse certificate: %s", err) |
| 107 | } |
| 108 | return fmt.Sprintf("(mspid=%s subject=%s issuer=%s serialnumber=%d)", id.Mspid, cert.Subject, cert.Issuer, cert.SerialNumber) |
| 109 | } |
| 110 | |
| 111 | func LogMessageForSerializedIdentities(signedData []*SignedData) (logMsg string) { |
| 112 | var identityMessages []string |