XMAVLink.Signing (xmavlink v0.12.1)

Copy Markdown View Source

Stateful MAVLink 2 signing policy helpers.

This module validates parsed signed frames against a shared key, tracks inbound replay state by {source_system, source_component, link_id}, and signs unsigned outbound MAVLink 2 frames with a per-connection timestamp. Optional timestamp load/save callbacks let applications preserve the local signing timestamp across restarts.

Summary

Types

new_error()

@type new_error() ::
  :invalid_accept_unsigned
  | :invalid_options
  | :invalid_link_id
  | :invalid_secret_key
  | :invalid_timestamp
  | :invalid_timestamp_load
  | :invalid_timestamp_save
  | :missing_link_id
  | :missing_secret_key
  | :timestamp_load_failed

sign_error()

@type sign_error() ::
  :already_signed
  | :checksum_invalid
  | :invalid_crc_extra
  | :invalid_link_id
  | :invalid_mavlink_2_frame
  | :invalid_secret_key
  | :invalid_timestamp
  | :mavlink_1_not_signable
  | :missing_crc_extra
  | :missing_mavlink_2_raw
  | :timestamp_save_failed
  | :timestamp_exhausted
  | :unsupported_incompatible_flags

stream_key()

@type stream_key() :: {0..255, 0..255, 0..255}

t()

@type t() :: %XMAVLink.Signing{
  accept_unsigned: boolean(),
  link_id: 0..255,
  secret_key: <<_::256>>,
  stream_timestamps: %{required(stream_key()) => timestamp()},
  timestamp: timestamp(),
  timestamp_load: timestamp_load() | nil,
  timestamp_save: timestamp_save() | nil
}

timestamp()

@type timestamp() :: 0..281_474_976_710_655

timestamp_load()

@type timestamp_load() :: (-> timestamp_load_result()) | {module(), atom(), [term()]}

timestamp_load_result()

@type timestamp_load_result() ::
  timestamp() | {:ok, timestamp() | nil} | nil | :error | {:error, term()}

timestamp_save()

@type timestamp_save() ::
  (timestamp() -> timestamp_save_result()) | {module(), atom(), [term()]}

timestamp_save_result()

@type timestamp_save_result() :: :ok | {:ok, term()} | :error | {:error, term()}

validate_error()

@type validate_error() ::
  :invalid_mavlink_2_frame
  | :invalid_secret_key
  | :signature_invalid
  | :signature_replay
  | :signature_too_old
  | :signed_frame_unsupported
  | :timestamp_save_failed
  | :unsigned_frame
  | :unsigned_frame_rejected

Functions

new(opts)

@spec new(nil | keyword()) :: {:ok, t() | nil} | {:error, new_error()}

now_timestamp()

@spec now_timestamp() :: timestamp()

sign_outbound(frame, signing)

@spec sign_outbound(XMAVLink.Frame.t(), t() | nil) ::
  {:ok, XMAVLink.Frame.t(), t() | nil} | {:error, sign_error(), t() | nil}

validate_inbound(frame, signing)

@spec validate_inbound(XMAVLink.Frame.t(), t() | nil) ::
  {:ok, XMAVLink.Frame.t(), t() | nil} | {:error, validate_error(), t() | nil}