Copyright 2013 The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

package packet

import (
	
	
	
	
	
)

const UserAttrImageSubpacket = 1
UserAttribute is capable of storing other types of data about a user beyond name, email and a text comment. In practice, user attributes are typically used to store a signed thumbnail photo JPEG image of the user. See RFC 4880, section 5.12.
NewUserAttributePhoto creates a user attribute packet containing the given images.
func ( ...image.Image) ( *UserAttribute,  error) {
	 = new(UserAttribute)
	for ,  := range  {
RFC 4880, Section 5.12.1.
		 := []byte{
			0x10, 0x00, // Little-endian image header length (16 bytes)
			0x01,       // Image header version 1
			0x01,       // JPEG
			0, 0, 0, 0, // 12 reserved octets, must be all zero.
			0, 0, 0, 0,
			0, 0, 0, 0}
		if _,  = .Write();  != nil {
			return
		}
		if  = jpeg.Encode(&, , nil);  != nil {
			return
		}
		.Contents = append(.Contents, &OpaqueSubpacket{
			SubType:  UserAttrImageSubpacket,
			Contents: .Bytes()})
	}
	return
}
NewUserAttribute creates a new user attribute packet containing the given subpackets.
func ( ...*OpaqueSubpacket) *UserAttribute {
	return &UserAttribute{Contents: }
}

RFC 4880, section 5.13
	,  := ioutil.ReadAll()
	if  != nil {
		return
	}
	.Contents,  = OpaqueSubpackets()
	return
}
Serialize marshals the user attribute to w in the form of an OpenPGP packet, including header.
func ( *UserAttribute) ( io.Writer) ( error) {
	var  bytes.Buffer
	for ,  := range .Contents {
		.Serialize(&)
	}
	if  = serializeHeader(, packetTypeUserAttribute, .Len());  != nil {
		return 
	}
	_,  = .Write(.Bytes())
	return
}
ImageData returns zero or more byte slices, each containing JPEG File Interchange Format (JFIF), for each photo in the user attribute packet.
func ( *UserAttribute) () ( [][]byte) {
	for ,  := range .Contents {
		if .SubType == UserAttrImageSubpacket && len(.Contents) > 16 {
			 = append(, .Contents[16:])
		}
	}
	return