Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
equal_test.go59 linesDownload Raw Back to rsa
1// Copyright 2020 The Go Authors. All rights reserved.2// Use of this source code is governed by a BSD-style3// license that can be found in the LICENSE file.4 5package rsa_test6 7import (8	"crypto"9	"crypto/rsa"10	"crypto/x509"11	"testing"12)13 14func TestEqual(t *testing.T) {15	t.Setenv("GODEBUG", "rsa1024min=0")16 17	private := test512Key18	public := &private.PublicKey19 20	if !public.Equal(public) {21		t.Errorf("public key is not equal to itself: %v", public)22	}23	if !public.Equal(crypto.Signer(private).Public().(*rsa.PublicKey)) {24		t.Errorf("private.Public() is not Equal to public: %v", public)25	}26	if !private.Equal(private) {27		t.Errorf("private key is not equal to itself: %v", private)28	}29 30	enc, err := x509.MarshalPKCS8PrivateKey(private)31	if err != nil {32		t.Fatal(err)33	}34	decoded, err := x509.ParsePKCS8PrivateKey(enc)35	if err != nil {36		t.Fatal(err)37	}38	if !public.Equal(decoded.(crypto.Signer).Public()) {39		t.Errorf("public key is not equal to itself after decoding: %v", public)40	}41	if !private.Equal(decoded) {42		t.Errorf("private key is not equal to itself after decoding: %v", private)43	}44 45	other := test512KeyTwo46	if public.Equal(other.Public()) {47		t.Errorf("different public keys are Equal")48	}49	if private.Equal(other) {50		t.Errorf("different private keys are Equal")51	}52 53	noPrecomp := *private54	noPrecomp.Precomputed = rsa.PrecomputedValues{}55	if !private.Equal(&noPrecomp) {56		t.Errorf("private key with no precomputation is not equal to itself: %v", private)57	}58}59 
codekingpro/portable-devtools · Team Ai