9elements/converged-security-suite

bg-prov template: Contains null

Closed this issue · 9 comments

Instead of arrays and strings the template contains JSON null from which it's impossible to infer the type. Fill in "" or [] instead.

This argument is false, because a empty array or quotationmarks would not help to give information about the type used.

Edit: null indicates a slice. [] would indicate an array (which would be wrong) and quotation marks would indicate a single value, this also would be wrong.

The JSON marshaler uses a string for HashStructure, hs_Buffer, which is a []byte.
The HashList, List field is a slice but JSON still uses [].

I dont get it.

The main culprit seems to be that the object contains nil slices, but it should contain empty slices.

Can we adapt the codegen to solve this issue, @xaionaro ?

The main culprit seems to be that the object contains nil slices, but it should contain empty slices.

Could you please provide an example of what do we have now and do we want to achieve? Could you also elaborate on the end reason of why the change is desirable (for me to better understand what to do)? Just we know field types using their paths. And there's no neat way to fully preserve typing in JSON (and I do not understand the positive impact of changing nil to []).

Can we adapt the codegen to solve this issue, @xaionaro ?

Looks like so. But I need to better understand what exactly do we want, first :)

For example take HashStructure

type HashStructure struct {
	HashAlg    Algorithm `default:"0x10" json:"hsAlg"`
	HashBuffer []byte    `json:"hsBuffer"`
}

HashStructure should be generated by New()-function and the field HashBuffer should be initialized by

HashBuffer := make([]byte,0)

Same for

// HashList describes multiple digests
type HashList struct {
	Size uint16          `rehashValue:"TotalSize()" json:"hlSize"`
	List []HashStructure `json:"hlList"`
}

Initialize List by

List := make([]HashStructure,0)

Makes no difference if there is nil, null or [] in the fields. There is no benefit for the reader to understand the field or get information about it's type as long as the field appears in the config.