Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crypto/tls: ConnectionState struct can not be json encoded in 1.11rc1 #27125

Closed
briankassouf opened this issue Aug 21, 2018 · 7 comments
Closed
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@briankassouf
Copy link

What version of Go are you using (go version)?

go1.11rc1

Does this issue reproduce with the latest release?

go1.11rc1 - yes
go1.10.3 - no

What operating system and processor architecture are you using (go env)?

darwin/amd64

What did you do?

package main

import (
	"crypto/tls"
	"encoding/json"
	"fmt"
)

func main() {
	connState := &tls.ConnectionState{}
	_, err := json.Marshal(connState)
	if err != nil {
		fmt.Println(err)
	}
}

Prints json: unsupported type: func(string, []uint8, int) ([]uint8, bool)

What did you expect to see?

in go1.10.3 nothing is printed

@FiloSottile
Copy link
Contributor

@bradfitz @andybons WDYT? Should we add a json:"-" tag? It does solve the issue for encoding/json, but not for all the other reflect based encodings.

Also, does it qualify for backport?

@FiloSottile FiloSottile added this to the Go1.11 milestone Aug 21, 2018
@FiloSottile FiloSottile added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Aug 21, 2018
@bradfitz
Copy link
Contributor

Yeah, let's add that json struct tag to that one field only in master & cherry-pick it to Go 1.11.

In the same CL, fix the typo in the documentation. The doc says "ExportKeyMaterial" but the field is named "ExportKeyingMaterial".

@FiloSottile FiloSottile added the NeedsFix The path to resolution is known, but the work has not been done. label Aug 21, 2018
@gopherbot gopherbot removed the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Aug 21, 2018
@FiloSottile FiloSottile modified the milestones: Go1.11, Go1.12 Aug 21, 2018
@bradfitz
Copy link
Contributor

Actually the ExportKeyingMaterial field is kinda weird. Why isn't it a method on the ConnectionState?

@bradfitz
Copy link
Contributor

Could we unexport that field instead and add a method that used the unexported field?

Then we're back to having no func types in that previously-data-only struct.

And then we don't have to add JSON stuff, and we don't need to worry about XML or protobuf, etc.

@gopherbot
Copy link

Change https://golang.org/cl/130535 mentions this issue: crypto/tls: hide ConnectionState.ExportKeyingMaterial from encoding/json

@FiloSottile
Copy link
Contributor

Yeah, I don't see any rationale in https://go-review.googlesource.com/c/go/+/85115, so I tend to agree. Does adding an unexported field to a struct that previously had none cause issues?

@bradfitz
Copy link
Contributor

@FiloSottile, adding an unexported field to a struct without them isn't something we do lightly. (going from fully public to partially private is a big step) But in this case I think it's better.

The other big thing we consider is breaking comparability (notably going from being able to use types as map keys to not being able to). But we already have slices in this, so that's already out the window.

I see no problems with a hidden field here, and I think a method would be better API anyway.

FiloSottile added a commit to FiloSottile/go that referenced this issue Oct 12, 2018
The unexported field is hidden from reflect based marshalers, which
would break otherwise. Also, make it return an error, as there are
multiple reasons it might fail.

Fixes golang#27125

Change-Id: I92adade2fe456103d2d5c0315629ca0256953764
Reviewed-on: https://go-review.googlesource.com/130535
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
FiloSottile added a commit to FiloSottile/go that referenced this issue Oct 12, 2018
The unexported field is hidden from reflect based marshalers, which
would break otherwise. Also, make it return an error, as there are
multiple reasons it might fail.

Fixes golang#27125

Change-Id: I92adade2fe456103d2d5c0315629ca0256953764
Reviewed-on: https://go-review.googlesource.com/130535
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
@golang golang locked and limited conversation to collaborators Aug 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants