NetMD.Session (NetMD v0.1.0)

Copy Markdown View Source

The secure session needed to download tracks, ported from netmd-js's MDSession.

Negotiates a session key by sending an enabling key block and exchanging nonces, then encrypts and streams track data.

{:ok, session} = NetMD.Session.start(device)
{:ok, %{track: n}} = NetMD.Session.download_track(session, track)
:ok = NetMD.Session.close(session)

Summary

Types

t()

An established secure session.

Functions

Forget the session key (errors ignored) and leave the secure session.

Download a track: set up the transfer, stream the encrypted packets, title the new track and commit it.

Enter the secure session and negotiate a session key.

Types

t()

@type t() :: %NetMD.Session{device: NetMD.Device.t(), key: <<_::64>>}

An established secure session.

Functions

close(session)

@spec close(t()) :: :ok | NetMD.Interface.error()

Forget the session key (errors ignored) and leave the secure session.

download_track(session, track, opts \\ [])

@spec download_track(t(), NetMD.Track.t(), keyword()) ::
  {:ok, %{track: non_neg_integer(), uuid: binary(), ccid: binary()}}
  | NetMD.Interface.error()

Download a track: set up the transfer, stream the encrypted packets, title the new track and commit it.

Options:

  • :disc_format - override the disc format byte derived from the track's wire format
  • :progress and :settle_ms - see NetMD.Interface.send_track/8

start(device, opts \\ [])

@spec start(
  NetMD.Device.t(),
  keyword()
) :: {:ok, t()} | NetMD.Interface.error()

Enter the secure session and negotiate a session key.

Accepts host_nonce: <<_::64>> for a deterministic exchange (tests); the default is random.