~juju-qa/ubuntu/xenial/juju/2.0-rc2

« back to all changes in this revision

Viewing changes to src/golang.org/x/crypto/openpgp/packet/public_key.go

  • Committer: Nicholas Skaggs
  • Date: 2016-09-30 14:39:30 UTC
  • mfrom: (1.8.1)
  • Revision ID: nicholas.skaggs@canonical.com-20160930143930-vwwhrefh6ftckccy
import upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
209
209
        return pk
210
210
}
211
211
 
 
212
// NewElGamalPublicKey returns a PublicKey that wraps the given elgamal.PublicKey.
 
213
func NewElGamalPublicKey(creationTime time.Time, pub *elgamal.PublicKey) *PublicKey {
 
214
        pk := &PublicKey{
 
215
                CreationTime: creationTime,
 
216
                PubKeyAlgo:   PubKeyAlgoElGamal,
 
217
                PublicKey:    pub,
 
218
                p:            fromBig(pub.P),
 
219
                g:            fromBig(pub.G),
 
220
                y:            fromBig(pub.Y),
 
221
        }
 
222
 
 
223
        pk.setFingerPrintAndKeyId()
 
224
        return pk
 
225
}
 
226
 
 
227
func NewECDSAPublicKey(creationTime time.Time, pub *ecdsa.PublicKey) *PublicKey {
 
228
        pk := &PublicKey{
 
229
                CreationTime: creationTime,
 
230
                PubKeyAlgo:   PubKeyAlgoECDSA,
 
231
                PublicKey:    pub,
 
232
                ec:           new(ecdsaKey),
 
233
        }
 
234
 
 
235
        switch pub.Curve {
 
236
        case elliptic.P256():
 
237
                pk.ec.oid = oidCurveP256
 
238
        case elliptic.P384():
 
239
                pk.ec.oid = oidCurveP384
 
240
        case elliptic.P521():
 
241
                pk.ec.oid = oidCurveP521
 
242
        default:
 
243
                panic("unknown elliptic curve")
 
244
        }
 
245
 
 
246
        pk.ec.p.bytes = elliptic.Marshal(pub.Curve, pub.X, pub.Y)
 
247
        pk.ec.p.bitLength = uint16(8 * len(pk.ec.p.bytes))
 
248
 
 
249
        pk.setFingerPrintAndKeyId()
 
250
        return pk
 
251
}
 
252
 
212
253
func (pk *PublicKey) parse(r io.Reader) (err error) {
213
254
        // RFC 4880, section 5.5.2
214
255
        var buf [6]byte