DEENESPTFRRUARHIKOZHNL

类 ara::crypto::Formatter

[SWS_CRYPT_50190] Upstream: RS_CRYPTO_02105

class Formatter {...};

Formatter object interface.

Header-Datei#include "ara/crypto/common/formatter.h"
Forwarding-Header#include "ara/crypto/crypto_fwd.h"
Scopenamespace ara::crypto

用户指南人工智能生成

支持在不同格式之间对加密数据进行线程安全的转换和序列化。
AI 生成 未审核 模型: gemini-3.8-flash-medium · 推理强度: medium · 温度: 不可控 · 提示词: f0bec470b702 来源 未决问题(2)
译自德文指南gemini-3.8-flash-low · 2026-10-13 · 德文原文

支持在不同格式之间对加密数据进行线程安全的转换和序列化。

接口 ara::crypto::Formatter 支持在原始格式、DER 格式和 PEM 格式之间对加密数据进行线程安全的转换和序列化 [SWS_CRYPT_50197]。在确定目标格式并通过方法 Convert 确定所需的缓冲区大小后,该方法将源数据传输到准备好的输出缓冲区中 [SWS_CRYPT_50198]。成功执行的重要前提是足够大的目标存储空间以及输入数据在形式上与配置的源格式一致。

上下文

接口 ara::crypto::Formatter 在模块 crypto 中定义了用于格式化、转换和序列化加密数据结构的一致接口。其主要任务是在考虑算法标识符 (AlgId) 的情况下,在纯原始数据 (kFormatRawValueOnly)、ASN.1-DER 编码 (kFormatDerEncoded) 以及文本 PEM 格式 (kFormatPemEncoded) 等表示形式之间转换有效载荷数据和加密对象 [SWS_CRYPT_50197]。在此,Formatter 充当加密对象与内存缓冲区之间的纽带,通过 ReadOnlyMemRegion 读取数据并在 ReadWriteMemRegion 中输出 [SWS_CRYPT_50198]。

生命周期

由于 ara::crypto::Formatter 声明为纯虚接口,因此它提供了规范的智能指针类型别名 Sptr(定义为 std::shared_ptr<Formatter>)用于引用和生命周期管理 [SWS_CRYPT_50191]。在实践中,该接口的具体实例应该通过上级加密组件的工厂方法提供。 问题 Q-99e96992d02b9c13 (未决)创建后,Formatter 最初处于未配置的初始状态,然后通过配置调用准备好进行转换。

关于执行环境,该接口通过始终使用 noexcept 并通过 Result 类型进行错误处理,保证了完全的异常安全 (exception safe) [SWS_CRYPT_50197], [SWS_CRYPT_50198], [SWS_CRYPT_50199]。此外,所有成员函数都被指定为线程安全 (thread-safe) [SWS_CRYPT_50197], [SWS_CRYPT_50198], [SWS_CRYPT_50199]。只要不发生并发的重新配置,这便允许多个线程并行对共享的 Formatter 实例进行读取和转换访问。

使用路径

ara::crypto::Formatter 的常规使用遵循由参数化、容量检查和转换组成的固定顺序:

  1. 格式配置:通过 SetFormatConfiguration 明确指定待处理数据的预期输入格式 (inputFormat)、所需输出格式 (outputFormat) 以及算法标识符 (algId) [SWS_CRYPT_50197]。
  2. 大小确定:在实际转换之前,应用程序调用 GetExportSize,以确定序列化对象在当前配置下所需的以字节为单位的精确内存大小 [SWS_CRYPT_50199]。这允许精准分配目标存储空间。
  3. 数据转换:最后,Convert 根据所做的配置将源数据从 ReadOnlyMemRegion 转换到目标缓冲区 ReadWriteMemRegion 中 [SWS_CRYPT_50198]。
使用 Formatter 的典型数据转换应用FormatterSetFormatConfiguration(inputFormat, outputFormat, algId)Result<void>GetExportSize()Result<std::size_t>(缓冲区大小)Convert(input, out)Result<void>

时序图:从格式选择、缓冲区大小确定到实际转换的典型转换流程。来源:[SWS_CRYPT_50197], [SWS_CRYPT_50199], [SWS_CRYPT_50198]

错误场景

ara::crypto::Formatter 的方法通过 ara::core::Result 类型的返回值确定性地发出错误状态信号。在此,为失败的操作定义了明确的回滚语义:

  • 不支持的格式:如果底层实现不支持指定的转换对或算法标识符,则 SetFormatConfiguration 返回错误码 ara::crypto::CryptoErrc::kUnsupportedFormat [SWS_CRYPT_50197]。
  • 无效输入数据:如果缓冲区中传入的原始数据不符合配置的格式或在语法上无效,则 Convert 失败并返回 ara::crypto::CryptoErrc::kInvalidArgument [SWS_CRYPT_50198]。
  • 目标缓冲区不足:如果提供的 ReadWriteMemRegion 对于序列化结果而言过小,则 Convert 中止并返回 ara::crypto::CryptoErrc::kInsufficientCapacity [SWS_CRYPT_50198]。通过预先使用 GetExportSize 进行查询可以专门防止此问题 [SWS_CRYPT_50199]。
  • 缺少预配置:虽然对于 GetExportSize 未列出标准化错误码 [SWS_CRYPT_50199],但推测必须预先通过 SetFormatConfiguration 建立有效配置,以便能够进行一致的大小确定或转换。 问题 Q-e7cf4306bc7cfb49 (未决)

本指南基于 AUTOSAR Adaptive Platform R25-11 规范(模块 crypto),由系统自动生成。

成员图

类图

Hohle Dreieckspfeile = Vererbung (zeigt zur Basisklasse); Klicken öffnet die jeweilige Klassenseite.

G nara__crypto__Formatter631 Formatter + Convert() + GetExportSize() + SetFormatConfiguration()

详细视图

请在大纲中选择一个条目。

方法

Convert 函数

Converts the data according to the previous configuration of the Formatter.

virtual ara::core::Result< void > Convert (ReadOnlyMemRegion input, ReadWriteMemRegion out) const noexcept=0;

Get the size in bytes of the object when serialized using the current configuration of the Formatter.

virtual ara::core::Result< std::size_t > GetExportSize () const noexcept=0;

Configure the formatter with the expected input format, output format, and the AlgId of the data to be formatted. The input and output format may be kFormatRawValueOnly, kFormatDer Encoded, or kFormatPemEncoded.

virtual ara::core::Result< void > SetFormatConfiguration (FormatId inputFormat, FormatId outputFormat, AlgId algId) noexcept=0;

类型别名

Sptr 类型别名

Smart pointer of the interface.

using Sptr = std::shared_ptr<Formatter>;

方法文档

函数 Convert [SWS_CRYPT_50198] Upstream: RS_CRYPTO_02112

virtual ara::core::Result< void > Convert (ReadOnlyMemRegion input, ReadWriteMemRegion out) const noexcept=0;

Converts the data according to the previous configuration of the Formatter.

AI 生成 未审核 模型: gemini-3.8-flash-medium · 推理强度: medium · 温度: 不可控 · 提示词: 96118f35b505 来源
译自德文指南gemini-3.8-flash-low · 2026-10-13 · 德文原文

接口ara::crypto::Formatter的纯虚成员函数Convert根据先前确定的 Formatter 对象配置执行数据的同步转换[SWS_CRYPT_50198]。声明可通过头文件#include "ara/crypto/common/formatter.h"获取[SWS_CRYPT_50198]。调用时,调用方通过类型为ReadOnlyMemRegion的缓冲区input传入原始格式的输入数据,并通过类型为ReadWriteMemRegion的可写缓冲区out接收写入的目标格式转换数据[SWS_CRYPT_50198]。

返回值定义为ara::core::Result<void>,指示成功或发生的错误[SWS_CRYPT_50198]。若转换期间发生问题,将采用具有以下特定错误代码的回滚语义[SWS_CRYPT_50198]:

  • ara::crypto::CryptoErrc::kInvalidArgument:若序列化的输入数据不符合指定格式,则返回此项[SWS_CRYPT_50198]。
  • ara::crypto::CryptoErrc::kInsufficientCapacity:当传入的输出缓冲区out容量过小而无法接收结果数据时发生[SWS_CRYPT_50198]。

在并发性和容错性方面,该方法被指定为线程安全(thread-safe)和异常安全(exception safe)[SWS_CRYPT_50198]。由于签名带有说明符const和noexcept,该操作不抛出 C++ 异常,且不改变 Formatter 实例的状态[SWS_CRYPT_50198]。

此使用说明由人工智能基于规范自动生成。

Header-Datei#include "ara/crypto/common/formatter.h"
Scopeclass ara::crypto::Formatter
Exception-Sicherheitexception safe
Thread-Sicherheitthread-safe

Parameter (in)

ParameterBeschreibung
inputan input buffer containing the data in the input format

Parameter (out)

ParameterBeschreibung
outan output buffer that the data will be written to in the output format

Rückgabewert

TypBeschreibung
ara::core::Result< void >An empty result or an error.

Fehler

FehlercodeBeschreibung
ara::crypto::CryptoErrc::kInvalidArgumentrollback_semantics if serialized does not conform to the specified format
ara::crypto::CryptoErrc::kInsufficientCapacityrollback_semantics if the output buffer is too small

Request a governed re-review of this record. The record is not changed immediately.

Record
AUTOSAR/AP/record/SWS_CRYPT_50198
Status
valid/unmigrated
Version
AUTOSAR/AP/record/SWS_CRYPT_50198@rel:R25-11#8e9d3a56
Content hash
8e9d3a56
Source
https://www.autosar.org/fileadmin/standards/R25-11/AP/AUTOSAR_AP_SWS_Cryptography.pdf#nameddest=SWS_CRYPT_50198
Status: valid/unmigrated Version: rel:R25-11#19644f36 Versionshistorie & Revisions (1 transition)
Current State
valid/unmigrated
Reason
mechanically backfilled by migriere_status_backfill.py -- no per-field curation history exists yet for this record
Campaign
2026-08-13-status-backfill
Active Version
AUTOSAR/AP/record/SWS_CRYPT_50198@rel:R25-11#19644f36
Point-in-Time History:
DateActorTransitionReason / RationaleCampaign
2026-08-13toolnone → valid/unmigratedmechanically backfilled by migriere_status_backfill.py -- no per-field curation history exists yet for this record2026-08-13-status-backfill

函数 GetExportSize [SWS_CRYPT_50199] Upstream: RS_CRYPTO_02112

virtual ara::core::Result< std::size_t > GetExportSize () const noexcept=0;

Get the size in bytes of the object when serialized using the current configuration of the Formatter.

Header-Datei#include "ara/crypto/common/formatter.h"
Scopeclass ara::crypto::Formatter
Exception-Sicherheitexception safe
Thread-Sicherheitthread-safe

Rückgabewert

TypBeschreibung
ara::core::Result<std::size_t >A result containing the size in bytes of the serialized object or an error.

Fehler

FehlercodeBeschreibung
This function does not specify any standardized errors.

Request a governed re-review of this record. The record is not changed immediately.

Record
AUTOSAR/AP/record/SWS_CRYPT_50199
Status
valid/unmigrated
Version
AUTOSAR/AP/record/SWS_CRYPT_50199@rel:R25-11#b12ed559
Content hash
b12ed559
Source
https://www.autosar.org/fileadmin/standards/R25-11/AP/AUTOSAR_AP_SWS_Cryptography.pdf#nameddest=SWS_CRYPT_50199
Status: valid/unmigrated Version: rel:R25-11#b96bc7d6 Versionshistorie & Revisions (1 transition)
Current State
valid/unmigrated
Reason
mechanically backfilled by migriere_status_backfill.py -- no per-field curation history exists yet for this record
Campaign
2026-08-13-status-backfill
Active Version
AUTOSAR/AP/record/SWS_CRYPT_50199@rel:R25-11#b96bc7d6
Point-in-Time History:
DateActorTransitionReason / RationaleCampaign
2026-08-13toolnone → valid/unmigratedmechanically backfilled by migriere_status_backfill.py -- no per-field curation history exists yet for this record2026-08-13-status-backfill

函数 SetFormatConfiguration [SWS_CRYPT_50197] Upstream: RS_CRYPTO_02112

virtual ara::core::Result< void > SetFormatConfiguration (FormatId inputFormat, FormatId outputFormat, AlgId algId) noexcept=0;

Configure the formatter with the expected input format, output format, and the AlgId of the data to be formatted. The input and output format may be kFormatRawValueOnly, kFormatDer Encoded, or kFormatPemEncoded.

Header-Datei#include "ara/crypto/common/formatter.h"
Scopeclass ara::crypto::Formatter
Exception-Sicherheitexception safe
Thread-Sicherheitthread-safe

Parameter (in)

ParameterBeschreibung
inputFormatthe input format
outputFormatthe output format
algIdthe AlgId of the data to be formatted

Rückgabewert

TypBeschreibung
ara::core::Result< void >An empty result or an error.

Fehler

FehlercodeBeschreibung
ara::crypto::CryptoErrc::kUnsupportedFormatrollback_semantics if the specified conversion is not supported

Request a governed re-review of this record. The record is not changed immediately.

Record
AUTOSAR/AP/record/SWS_CRYPT_50197
Status
valid/unmigrated
Version
AUTOSAR/AP/record/SWS_CRYPT_50197@rel:R25-11#826bbd3b
Content hash
826bbd3b
Source
https://www.autosar.org/fileadmin/standards/R25-11/AP/AUTOSAR_AP_SWS_Cryptography.pdf#nameddest=SWS_CRYPT_50197
Status: valid/unmigrated Version: rel:R25-11#25ee4601 Versionshistorie & Revisions (1 transition)
Current State
valid/unmigrated
Reason
mechanically backfilled by migriere_status_backfill.py -- no per-field curation history exists yet for this record
Campaign
2026-08-13-status-backfill
Active Version
AUTOSAR/AP/record/SWS_CRYPT_50197@rel:R25-11#25ee4601
Point-in-Time History:
DateActorTransitionReason / RationaleCampaign
2026-08-13toolnone → valid/unmigratedmechanically backfilled by migriere_status_backfill.py -- no per-field curation history exists yet for this record2026-08-13-status-backfill

类型别名文档

类型别名 Sptr [SWS_CRYPT_50191] Upstream: RS_CRYPTO_02306

using Sptr = std::shared_ptr<Formatter>;

Smart pointer of the interface.

Header-Datei#include "ara/crypto/common/formatter.h"
Scopeclass ara::crypto::Formatter
SymbolSptr

Request a governed re-review of this record. The record is not changed immediately.

Record
AUTOSAR/AP/record/SWS_CRYPT_50191
Status
valid/unmigrated
Version
AUTOSAR/AP/record/SWS_CRYPT_50191@rel:R25-11#32565bc3
Content hash
32565bc3
Source
https://www.autosar.org/fileadmin/standards/R25-11/AP/AUTOSAR_AP_SWS_Cryptography.pdf#nameddest=SWS_CRYPT_50191
Status: valid/unmigrated Version: rel:R25-11#869e375a Versionshistorie & Revisions (1 transition)
Current State
valid/unmigrated
Reason
mechanically backfilled by migriere_status_backfill.py -- no per-field curation history exists yet for this record
Campaign
2026-08-13-status-backfill
Active Version
AUTOSAR/AP/record/SWS_CRYPT_50191@rel:R25-11#869e375a
Point-in-Time History:
DateActorTransitionReason / RationaleCampaign
2026-08-13toolnone → valid/unmigratedmechanically backfilled by migriere_status_backfill.py -- no per-field curation history exists yet for this record2026-08-13-status-backfill