Skip to content

Commit b43d54e

Browse files
Add mapping function
Signed-off-by: Yogesh Deshpande <[email protected]>
1 parent adb9e5f commit b43d54e

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2026 Contributors to the Veraison project.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package compositeevidenceparser
5+
6+
import (
7+
"fmt"
8+
"mime"
9+
)
10+
11+
// present MediaType to Composite Parser is maintained locally within the compositeevidenceparser package
12+
var mtToCeParser = map[string]ICompositeEvidenceParser{
13+
"application/cmw-collection+cbor": &cmwParser{},
14+
"application/cmw-collection+json": &cmwParser{},
15+
}
16+
17+
func GetParserFromMediaType(mt string) (ICompositeEvidenceParser, error) {
18+
// Check if its a valid mediaType
19+
if _, _, err := mime.ParseMediaType(mt); err != nil {
20+
return nil, fmt.Errorf("bad media type: %w", err)
21+
}
22+
switch mt {
23+
case "application/cmw-collection+cbor", "application/cmw-collection+json":
24+
return mtToCeParser[mt], nil
25+
default:
26+
return nil, fmt.Errorf("unsupported media type:%s", mt)
27+
}
28+
}

0 commit comments

Comments
 (0)