M3U8::SessionKeyItem
Inherits M3U8::Encryptable / M3U8::Concern / Reference / Object
SessionKeyItem represents a set of attributes for the EXT-X-SESSION-KEY tag,
which is used in HTTP Live Streaming (HLS) to specify encryption keys that
apply to a session of Media Segments.
According to RFC 8216, Section 4.3.4.5,
the EXT-X-SESSION-KEY tag provides information such as the encryption METHOD,
the URI to obtain the key, the Initialization Vector IV, and optionally the
KEYFORMAT and KEYFORMATVERSIONS.
Example of an EXT-X-SESSION-KEY tag:
#EXT-X-SESSION-KEY:METHOD=AES-128,URI="http://test.key",IV=D512BBF,KEYFORMAT="identity",KEYFORMATVERSIONS="1/3"
All attributes defined for the EXT-X-KEY tag (RFC 8216, Section 4.3.2.4) are
also defined for the EXT-X-SESSION-KEY, except that the value of the
METHOD attribute MUST NOT be NONE.
This class leverages the Encryptable module to parse and format these attributes.
Class methods
Parses a text string representing an EXT-X-SESSION-KEY tag and returns a new
SessionKeyItem instance.
It extracts the attribute list from the tag line using parse_attributes
(from the M3U8::Concern module), then converts the extracted values using
Encryptable.convert_key.
Example:
text = %(#EXT-X-SESSION-KEY:METHOD=AES-128,URI="http://test.key",IV=D512BBF,KEYFORMAT="identity",KEYFORMATVERSIONS="1/3")
SessionKeyItem.parse(text)
# => #<M3U8::SessionKeyItem:0x7e4a9ab264c0
# @iv="D512BBF",
# @key_format="identity",
# @key_format_versions="1/3",
# @method="AES-128",
# @uri="http://test.key">
Instance methods
Returns the string representation of the EXT-X-SESSION-KEY tag.
The output is generated by concatenating the formatted encryption key
attributes (provided by the Encryptable module) with the tag identifier.
Example:
options = {
method: "AES-128",
uri: "http://test.key",
iv: "D512BBF",
key_format: "identity",
key_format_versions: "1/3",
}
SessionKeyItem.new(options).to_s
# => "#EXT-X-SESSION-KEY:METHOD=AES-128,URI=\"http://test.key\",IV=D512BBF,KEYFORMAT=\"identity\",KEYFORMATVERSIONS=\"1/3\""