module M3U8::Encryptable

Overview

Provides common functionality for constructing encryption key tags in HTTP Live Streaming (HLS).

According to RFC 8216, Section 4.3.2.4, the EXT-X-KEY tag specifies the encryption parameters for Media Segments in an HLS playlist. This tag includes several attributes:

#EXT-X-KEY:METHOD=AES-128,URI="http://test.key",IV=D512BBF,KEYFORMAT="identity",KEYFORMATVERSIONS="1/3"

This module provides helper methods that convert parameter hashes into the correctly formatted attribute string for inclusion in an EXT-X-KEY tag.

Direct including types

Defined in:

m3u8/encryptable.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(params : NamedTuple = NamedTuple.new) #

Alternative constructor that accepts a NamedTuple with symbol keys.

Example:

options = {
  method:              "AES-128",
  uri:                 "https://example.com/key",
  iv:                  "0x1a2b3c",
  key_format:          "identity",
  key_format_versions: "1",
}

class Something
  include Encryptable
end

Something.new(options)
# => #<App::Something:0x78b71f3a9380
#     @iv="0x1a2b3c",
#     @key_format="identity",
#     @key_format_versions="1",
#     @method="AES-128",
#     @uri="https://example.com/key">

[View source]
def self.new(method = "", uri = nil, iv = nil, key_format = nil, key_format_versions = nil) #

Initializes a new Encryptable instance with the given parameters.

Parameters:

  • #method: The encryption method (required).
  • #uri: The URI for the key (optional).
  • #iv: The Initialization Vector IV (optional).
  • #key_format: The key format (optional).
  • #key_format_versions: The supported key format versions (optional).
class Something
  include Encryptable
end

Something.new(method: "AES-128", uri: "https://example.com/key")
# => #<App::Something:0x7cae3cdbb2c0
#     @iv=nil,
#     @key_format=nil,
#     @key_format_versions=nil,
#     @method="AES-128",
#     @uri="https://example.com/key">

[View source]

Class Method Detail

def self.convert_key(params) #

Converts a hash of parameters (with keys in uppercase, as in a playlist) into a new hash with symbolized keys for internal use.

Expected keys are:

  • METHOD
  • URI
  • IV
  • KEYFORMAT
  • KEYFORMATVERSIONS.

Returns a NamedTuple.

Example:

options = {
  "METHOD"            => "AES-128",
  "URI"               => "http://test.key",
  "IV"                => "D512BBF",
  "KEYFORMAT"         => "identity",
  "KEYFORMATVERSIONS" => "1/3",
}
Encryptable.convert_key(options)
# => {method: "AES-128",
#     uri: "http://test.key",
#     iv: "D512BBF",
#     key_format: "identity",
#     key_format_versions: "1/3"}

[View source]

Instance Method Detail

def attributes_to_s #

Constructs a string representation of the encryption key attributes.

The output is a comma-separated list of attribute assignments, suitable for inclusion in an EXT-X-KEY tag.

Example:

class Something
  include Encryptable
end

Something.new(method: "AES-128", uri: "https://example.com/key").attributes_to_s
# => "METHOD=AES-128,URI=\"https://example.com/key\""

[View source]
def iv : String | Nil #

The value is a hexadecimal-sequence that specifies a 128-bit unsigned integer Initialization Vector IV to be used with the key.


[View source]
def iv=(iv : String | Nil) #

The value is a hexadecimal-sequence that specifies a 128-bit unsigned integer Initialization Vector IV to be used with the key.


[View source]
def key_format : String | Nil #

The value is a string that specifies how the key is represented in the resource identified by the URI;


[View source]
def key_format=(key_format : String | Nil) #

The value is a string that specifies how the key is represented in the resource identified by the URI;


[View source]
def key_format_versions : String | Nil #

The value is a string containing one or more positive integers separated by the / character (for example, 1, 1/2, or 1/2/5).


[View source]
def key_format_versions=(key_format_versions : String | Nil) #

The value is a string containing one or more positive integers separated by the / character (for example, 1, 1/2, or 1/2/5).


[View source]
def method : String #

The value is a string that specifies the encryption method.

The methods defined are: NONE, AES-128, and SAMPLE-AES. An encryption method of NONE means that Media Segments are not encrypted.


[View source]
def method=(method : String) #

The value is a string that specifies the encryption method.

The methods defined are: NONE, AES-128, and SAMPLE-AES. An encryption method of NONE means that Media Segments are not encrypted.


[View source]
def uri : String | Nil #

The value is a string containing a URI that specifies how to obtain the key.


[View source]
def uri=(uri : String | Nil) #

The value is a string containing a URI that specifies how to obtain the key.


[View source]