// Format gives you the partial key in the canonical representation including // ----BEGIN/END headers. func (k *PartialKey) String() string { b := new(buffer.Buffer) k.WriteBuffer(b) if b.Error != nil { panic(errors.New("invalid partial key: " + b.Error.Error())) } return HEADER + "\n" + lineWrap(b.String(), 64) + FOOTER + "\n" }
// String produces the line-wrapped base-64 version of the challenge, // suitable for being passed to NewSignRequest() func (request *SignRequest) String() string { b := new(buffer.Buffer) request.WriteBuffer(b) if b.Error != nil { panic(errors.New("invalid sign request: " + b.Error.Error())) } return SIGN_REQUEST_HEADER + "\n" + lineWrap(b.String(), 64) + SIGN_REQUEST_FOOTER + "\n" }
// String returns the public key in the same format as used by ssh func (p *PublicKey) String() string { b := new(buffer.Buffer) p.WriteBuffer(b) if b.Error != nil { panic(errors.New("invalid public key: " + b.Error.Error())) } return PUBLIC_KEY_TYPE + " " + b.String() + "\n" }
// ReadBuffer reads the public key from a buffer. func (p *PublicKey) ReadBuffer(b *buffer.Buffer) error { t := b.ScanString() e := b.ScanMPInt() n := b.ScanMPInt() if t != PUBLIC_KEY_TYPE { return ErrPublicKeyFormat } if e.Cmp(big.NewInt(EXPONENT)) != 0 { return ErrPublicKeyFormat } p.E = EXPONENT p.N = n return nil }
// ReadBuffer reads a SignRequest from a buffer. func (request *SignRequest) ReadBuffer(b *buffer.Buffer) error { publicKey := new(PublicKey) err := publicKey.ReadBuffer(b) if err != nil { return err } msg := b.ScanMPInt() if msg.Cmp(publicKey.N) >= 0 { return errors.New("cannot sign message > N") } request.Key = publicKey request.M = msg return nil }
// WriteBuffer writes the PartialKey to a buffer func (k *PartialKey) WriteBuffer(b *buffer.Buffer) { b.AddString(KEY_TYPE) b.AddMPInt(big.NewInt(int64(k.E))) b.AddMPInt(k.N) b.AddMPInt(k.D) }
// WriteBuffer writes the public key to a buffer. func (p *PublicKey) WriteBuffer(b *buffer.Buffer) { b.AddString(PUBLIC_KEY_TYPE) b.AddMPInt(big.NewInt(int64(p.E))) b.AddMPInt(p.N) }
func (request *SignRequest) WriteBuffer(b *buffer.Buffer) { request.Key.WriteBuffer(b) b.AddMPInt(request.M) }
func (a *AuthRequest) unsignedBuffer() *buffer.Buffer { b := buffer.Buffer{} b.AddBuffer(a.ChallengeBuffer) b.AddString(a.RequestUrl) b.AddString(a.Username) b.AddString(a.ServiceName) b.AddString(a.AuthMethod) b.AddString(a.SigningAlgorithm) // b.AddVarBytes(publicKeyBytes(a.PublicKey)) panic("todo") return &b }