Skip to content

Commit

Permalink
Merge pull request #670 from smallstep/herman/fix-tpm-manufacturer-as…
Browse files Browse the repository at this point in the history
…cii-lookup

Fix TPM manufacturer lookup for names with a space (`0x20`) character
  • Loading branch information
hslatman authored Jan 9, 2025
2 parents 466f9a5 + 4519939 commit ecbfacf
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions tpm/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ type Manufacturer struct {
// String returns a textual representation of the TPM
// manufacturer. An example looks like this:
//
// ST Microelectronics (STM, 53544D20, 1398033696)
// ST Microelectronics (<STM >, 53544D20, 1398033696)
func (m Manufacturer) String() string {
return fmt.Sprintf("%s (%s, %s, %d)", m.Name, m.ASCII, m.Hex, m.ID)
return fmt.Sprintf("%s (<%s>, %s, %d)", m.Name, m.ASCII, m.Hex, m.ID)
}

// GetManufacturerByID returns a Manufacturer based on its Manufacturer ID
Expand Down
4 changes: 2 additions & 2 deletions tpm/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ func Test_GetManufacturerByID(t *testing.T) {
func TestManufacturer_String(t *testing.T) {
m := Manufacturer{
Name: "ST Microelectronics",
ASCII: "STM",
ASCII: "STM ",
ID: 1398033696,
Hex: "53544D20",
}
want := "ST Microelectronics (STM, 53544D20, 1398033696)"
want := "ST Microelectronics (<STM >, 53544D20, 1398033696)"
if got := m.String(); got != want {
t.Errorf("Manufacturer.String() = %v, want %v", got, want)
}
Expand Down
2 changes: 1 addition & 1 deletion tpm/manufacturer/manufacturers.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func GetEncodings(id ID) (ascii, hexa string) {
// GetNameByASCII returns the manufacturer name based on its
// ASCII identifier.
func GetNameByASCII(ascii string) string {
if name, ok := manufacturerByASCII[ascii]; ok {
if name, ok := manufacturerByASCII[strings.TrimSpace(ascii)]; ok {
return name
}
return "unknown"
Expand Down
2 changes: 2 additions & 0 deletions tpm/manufacturer/manufacturers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func Test_GetEncodings(t *testing.T) {
}{
{"infineon", 1229346816, "IFX"},
{"intel", 1229870147, "INTC"},
{"stm", 1398033696, "STM "},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand All @@ -33,6 +34,7 @@ func Test_GetNameByASCII(t *testing.T) {
}{
{"infineon", "IFX", "Infineon"},
{"intel", "INTC", "Intel"},
{"stm", "STM ", "ST Microelectronics"},
{"unknown", "0000", "unknown"},
}
for _, tt := range tests {
Expand Down

0 comments on commit ecbfacf

Please sign in to comment.