搜尋分類、套件與程式碼儲存庫

套件詳情v1.6.8

asn1lib

適用於 Dart 的 ASN1 解析器庫。將 ASN1 物件編碼/解碼為 BER 字節

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
234萬
喜歡數
27
Pub 分數
150

安裝套件

flutter pub add asn1lib

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

asn1lib 是一個 Dart 庫,用於使用 BER(基本編碼規則)解析和生成 ASN.1(抽象語法表示法一)資料結構。它能夠將 ASN.1 物件編碼和解碼為二進位 BER 字節串流,適用於依賴 ASN.1 的協定,例如 X.509 憑證、LDAP 和 SNMP。該庫支援所有主要平台,包括 Android、iOS、Web、macOS、Windows 和 Linux。它提供了一個乾淨且類型安全的 API,用於處理複雜的嵌套 ASN.1 結構。

適用情境

  • 解析 X.509 憑證
  • 處理 LDAP 數據
  • 實現SNMP客戶端
  • 處理加密資料格式
  • 與舊系統互操作

主要特色

  • BER 編碼/解碼
  • 對嵌套的 ASN.1 結構的支援
  • 跨平台相容性
  • 類型安全的物件映射
  • 輕量且依賴極少

適合對象

  • 開發人員在使用加密標準
  • 處理基於ASN.1協議的系統整合商
  • 需要安全資料交換的應用程式

使用建議

  • 需要了解 ASN.1 和 BER
  • 不適合簡單的 JSON 類型資料
  • 與主流庫相比,文件較少

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

ASN.1 Parser for Dart

Encodes & decodes ASN1 using BER encoding.

Samples

Encoding
import 'package:asn1lib/asn1lib.dart';

var s = ASN1Sequence();
s.add(ASN1Integer(23));
s.add(ASN1OctetString('This is a test'));
s.add(ASN1Boolean(true));

// GET the BER Stream
var bytes = s
.
encodedBytes;
Decoding
import 'package:asn1lib/asn1lib.dart';

// e.g. bytes from the Encoding Example
var p = ASN1Parser(bytes);
var s2 = p.nextObject();
// s2 is a sequence...


// relaxed parsing, returning a generic ASN1Object from (yet) unsupported structures, instead of throwing
var p2 = ASN1Parser(bytes, relaxedParsing: true);
var s3 = p2.nextObject();
// s3 is a sequence...

ASN1 Object classes

The library has been most thoroughly tested against ASN1 primitive class types, such as strings, integers, sequences and sets.

There is minimal support for ASN1 Application, Context-specific and Private classes. If the parser encounters these tags, it will wrap them in an a corresponding object ( ASN1Application, ASN1ContextSpecific, ASN1Private). You can force decode these to another type, by doing something like this:

    var s = parser.nextObject();
    // We expect this is a context-specific class
    expect(s, isA<ASN1ContextSpecific>());
    // which is also an ASN1Object...
    expect(s, isA<ASN1Object>());
    // We expect this is a sequence, so "recast" to a sequence type
    var sequence = ASN1Sequence.fromBytes(s.encodedBytes);
    expect(sequence, isA<ASN1Sequence>());

Breaking Changes

As of 1.6, the default encoding of ASN1OctetString("some string") has changed. It now encodes octets using utf8 encoding. This is different than Dart's default utf16 encoding.

If you need to encode to utf16, you should convert to bytes first:

var x = ASN1OctetString(Uint8List.fromList('some string'.codeUnits));
// new getter
var y = x.utf16StringValue;

The getter ASN1OctetString.stringValue is deprecated. You should use ASN1OctetString.utf8StringValue or ASN1OctetString.utf16StringValue instead.

Issues

ASN1 parsing is complex, so bugs are expected. If you find a bug, please provide a test case that demonstrates the issue, along with the expected output. Bonus points if it is formatted as a dart test.

References

  • https://letsencrypt.org/docs/a-warm-welcome-to-asn1-and-der/
  • https://luca.ntop.org/Teaching/Appunti/asn1.html
  • https://ldap.com/ldapv3-wire-protocol-reference-asn1-ber/

所屬分類

原始碼儲存庫

使用此套件的專案