// PublicKeyFromString creates a new public key based on the string data "<type> <key> <description>"
PublicKeyFromString creates a new public key based on the string data "  "
// PublicKeyFromString creates a new public key based on the string data " <type > <key > <description > "
func PublicKeyFromString(data string) (*PubKey, error) {
	if !strings.Contains(data, " ") {
		return nil, errIncorrectKeyFormat
	}
	parts := strings.SplitN(data, " ", 3)
	if len(parts) == 2 {
		parts = append(parts, "")
	}
	if len(parts) != 3 {
		return nil, errIncorrectKeyFormat
	}
	pk := &PubKey{}
	var err error
	pk.Type, err = FindKeyType(parts[0])
	if err != nil {
		return nil, errUnsupportedKeyType
	}
	pk.S = strings.TrimSpace(parts[1])
	pk.B = []byte(pk.S)
	pk.Description = parts[2]
	buf := make([]byte, base64.StdEncoding.DecodedLen(len(pk.B)))
	n, err := base64.StdEncoding.Decode(buf, pk.B)
	if err != nil {
		return nil, errIncorrectKeyFormat
	}
	pk.K, err = pk.Type.ParsePublicKeyData(buf[:n])
	if err != nil {
		return nil, errIncorrectKeyFormat
	}
	return pk, nil
}
func PublicKeyFromString ( data string ) ( * PubKey , error ) { if ! strings . Contains ( data , " " ) { return nil , errIncorrectKeyFormat } parts := strings . SplitN ( data , " " , 3 ) if len ( parts ) == 2 { parts = append ( parts , " " ) } if len ( parts ) != 3 { return nil , errIncorrectKeyFormat } pk := & PubKey { } var err error pk . Type , err = FindKeyType ( parts [ 0 ] ) if err != nil { return nil , errUnsupportedKeyType } pk . S = strings . TrimSpace ( parts [ 1 ] ) pk . B = [ ] byte ( pk . S ) pk . Description = parts [ 2 ] buf := make ( [ ] byte , base64 . StdEncoding . DecodedLen ( len ( pk . B ) ) ) n , err := base64 . StdEncoding . Decode ( buf , pk . B ) if err != nil { return nil , errIncorrectKeyFormat } pk . K , err = pk . Type . ParsePublicKeyData ( buf [ : n ] ) if err != nil { return nil , errIncorrectKeyFormat } return pk , nil }
PublicKeyFromString creates a new public key based on the string data "  "
PublicKeyFromString creates a new public key based on the string data " "
// <type> <data> // Find the correct key type // Set values // Decode base64 before we parse to key // Parse key