File: encryptable.go

package info (click to toggle)
golang-github-etherlabsio-go-m3u8 1.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 348 kB
  • sloc: makefile: 3
file content (46 lines) | stat: -rw-r--r-- 1,311 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package m3u8

import (
	"fmt"
	"strings"
)

// Encryptable is common representation for KeyItem and SessionKeyItem
type Encryptable struct {
	Method            string
	URI               *string
	IV                *string
	KeyFormat         *string
	KeyFormatVersions *string
}

// NewEncryptable takes an attributes map and returns an *Encryptable
func NewEncryptable(attributes map[string]string) *Encryptable {
	return &Encryptable{
		Method:            attributes[MethodTag],
		URI:               pointerTo(attributes, URITag),
		IV:                pointerTo(attributes, IVTag),
		KeyFormat:         pointerTo(attributes, KeyFormatTag),
		KeyFormatVersions: pointerTo(attributes, KeyFormatVersionsTag),
	}
}

func (e *Encryptable) String() string {
	var slice []string

	slice = append(slice, fmt.Sprintf(formatString, MethodTag, e.Method))
	if e.URI != nil {
		slice = append(slice, fmt.Sprintf(quotedFormatString, URITag, *e.URI))
	}
	if e.IV != nil {
		slice = append(slice, fmt.Sprintf(formatString, IVTag, *e.IV))
	}
	if e.KeyFormat != nil {
		slice = append(slice, fmt.Sprintf(quotedFormatString, KeyFormatTag, *e.KeyFormat))
	}
	if e.KeyFormatVersions != nil {
		slice = append(slice, fmt.Sprintf(quotedFormatString, KeyFormatVersionsTag, *e.KeyFormatVersions))
	}

	return strings.Join(slice, ",")
}