Copyright 2011 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 (
	
	
	
	
	
	
)
OnePassSignature represents a one-pass signature packet. See RFC 4880, section 5.4.
type OnePassSignature struct {
	SigType    SignatureType
	Hash       crypto.Hash
	PubKeyAlgo PublicKeyAlgorithm
	KeyId      uint64
	IsLast     bool
}

const onePassSignatureVersion = 3

func ( *OnePassSignature) ( io.Reader) ( error) {
	var  [13]byte

	_,  = readFull(, [:])
	if  != nil {
		return
	}
	if [0] != onePassSignatureVersion {
		 = errors.UnsupportedError("one-pass-signature packet version " + strconv.Itoa(int([0])))
	}

	var  bool
	.Hash,  = s2k.HashIdToHash([2])
	if ! {
		return errors.UnsupportedError("hash function: " + strconv.Itoa(int([2])))
	}

	.SigType = SignatureType([1])
	.PubKeyAlgo = PublicKeyAlgorithm([3])
	.KeyId = binary.BigEndian.Uint64([4:12])
	.IsLast = [12] != 0
	return
}
Serialize marshals the given OnePassSignature to w.
func ( *OnePassSignature) ( io.Writer) error {
	var  [13]byte
	[0] = onePassSignatureVersion
	[1] = uint8(.SigType)
	var  bool
	[2],  = s2k.HashToHashId(.Hash)
	if ! {
		return errors.UnsupportedError("hash type: " + strconv.Itoa(int(.Hash)))
	}
	[3] = uint8(.PubKeyAlgo)
	binary.BigEndian.PutUint64([4:12], .KeyId)
	if .IsLast {
		[12] = 1
	}

	if  := serializeHeader(, packetTypeOnePassSignature, len());  != nil {
		return 
	}
	,  := .Write([:])
	return