-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Yogesh Deshpande <[email protected]>
- Loading branch information
1 parent
9a6edcb
commit 8e449ab
Showing
11 changed files
with
429 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright 2024 Contributors to the Veraison project. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package comid | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
const BytesType = "bytes" | ||
|
||
type TaggedBytes []byte | ||
|
||
func NewBytes(val any) (*TaggedBytes, error) { | ||
var ret TaggedBytes | ||
|
||
if val == nil { | ||
return &ret, nil | ||
} | ||
|
||
switch t := val.(type) { | ||
case string: | ||
b := []byte(t) | ||
ret = TaggedBytes(b) | ||
case []byte: | ||
ret = TaggedBytes(t) | ||
case *[]byte: | ||
ret = TaggedBytes(*t) | ||
default: | ||
return nil, fmt.Errorf("unexpected type for bytes: %T", t) | ||
} | ||
return &ret, nil | ||
} | ||
|
||
func (o TaggedBytes) String() string { | ||
return string(o) | ||
} | ||
|
||
func (o TaggedBytes) Valid() error { | ||
return nil | ||
} | ||
|
||
func (o TaggedBytes) Type() string { | ||
return "bytes" | ||
} | ||
|
||
func (o TaggedBytes) Bytes() []byte { | ||
|
||
return o | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.