You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
546 B

package telegram
import (
"crypto/rsa"
"encoding/pem"
"github.com/go-faster/errors"
"github.com/gotd/td/internal/crypto"
"github.com/gotd/td/tg"
)
func parseCDNKeys(keys ...tg.CDNPublicKey) ([]*rsa.PublicKey, error) {
r := make([]*rsa.PublicKey, 0, len(keys))
for _, key := range keys {
block, _ := pem.Decode([]byte(key.PublicKey))
if block == nil {
continue
}
key, err := crypto.ParseRSA(block.Bytes)
if err != nil {
return nil, errors.Wrap(err, "parse RSA from PEM")
}
r = append(r, key)
}
return r, nil
}