패키지, 저장소 및 앱 카테고리 검색

패키지 상세v1.6.8

asn1lib

Dart용 ASN1 파서 라이브러리입니다. ASN1 객체를 BER 바이트로 인코딩/디코딩합니다

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
234만
좋아요
27
Pub 점수
150

패키지 설치

flutter pub add asn1lib

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

asn1lib은 BER(기본 인코딩 규칙)을 사용하여 ASN.1(추상 구문 표기법 1) 데이터 구조를 분석하고 생성하기 위한 Dart 라이브러리입니다. 이는 ASN.1 객체를 바이너리 BER 바이트 스트림으로 인코딩하고 디코딩할 수 있게 해주며, X.509 인증서, LDAP, SNMP와 같은 ASN.1에 의존하는 프로토콜 작업에 적합합니다. 이 라이브러리는 Android, iOS, Web, macOS, Windows, Linux 등 모든 주요 플랫폼을 지원합니다. 복잡한 중첩된 ASN.1 구조를 처리하기 위한 깔끔하고 타입 안전한 API를 제공합니다.

사용 사례

  • 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/

카테고리

소스 저장소

이 패키지를 사용하는 프로젝트