The implementation of Equal() expects the PublicKey argument to be a
pointer to an rsa.PublicKey. If you do the following it works:
if !key.PublicKey.Equal(&key.PublicKey) {
t.Fatal("key mismatch")
}
It should probably be documented as such.
On Tuesday, October 27, 2020 at 12:01:53 PM UTC-4 [email protected]
wrote:
> My formulation was not clear. The test fails, and it reports a key
> mismatch.
>
> Le mardi 27 octobre 2020 à 16:21:05 UTC+1, [email protected] a
> écrit :
>
>> I have the following test that fails reporting a key mismatch.
>>
>> func TestKeyEqual(t *testing.T) {
>> key, err := rsa.GenerateKey(rand.Reader, 2048)
>> if err != nil {
>> t.Fatal("failed generating private key: ", err)
>> }
>> if !key.PublicKey.Equal(key.PublicKey) {
>> t.Fatal("key mismatch")
>> }
>> }
>>
>> Why is that ? Shouldn’t it return true ?
>>
>> Initially I compared key after save and reload read, and since it failed,
>> I just tested the same key for equality to verify that Equal was working as
>> expected. Apparently it does not or I’m doing something wrong.
>>
>
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/0bc95725-3dc1-4b68-a9bb-351ed7746287n%40googlegroups.com.