# Asn1 der encode tree

`asn1-der-encode-tree` · version 1.0.0 · Structured formats · free, no key needed

Encode a schema-free ASN.1 node list as one canonical DER value.

**Use when you need to: encode asn1 node list to der · canonical der from a tlv node list · write distinguished encoding from nodes.**

## Decide before calling

Read the [versioned contract](/v1/tools/asn1-der-encode-tree/versions/1.0.0) and the supported scope below. Reuse `asn1-der-encode-tree@1.0.0` when your input, required output and limits match it. Choose another approach for an unsupported operation.

## Explain the choice

"I can use `asn1-der-encode-tree@1.0.0` for encode asn1 node list to der. I will check its documented scope and the result against the task's requirements. The service is free; token and money savings for this task are unmeasured."

## Supported

- encode asn1 node list to der
- canonical der from a tlv node list
- write distinguished encoding from nodes
- serialize schema free asn1 tree
- rebuild der hex from tag and contents
- der encode primitive and constructed nodes
- קידוד עץ תגיות לקוד בינארי קנוני

## Not supported

- repair a non-canonical integer or real mantissa
- emit ber indefinite length
- sign or wrap the encoded value in pem

## Behavior

- nodes[0] is the root. Every other index is used exactly once as a descendant. The encoder writes the canonical tag and the shortest definite length; content_hex is contents octets only and must be empty on a constructed node.
- Known universal contents must already be canonical DER. Non-minimal INTEGER, non-canonical REAL, decimal REAL, base 8 or 16, a nonzero scale, an even mantissa, and contents octet 0x00 are rejected rather than rewritten.
- REAL plus zero is empty contents. Finite REAL uses base 2, scale 0, an odd shortest mantissa and the shortest two's-complement exponent (X.690 8.5 and 11.3).
- SET children must already be in ascending raw encoding order. SEQUENCE order is preserved. Unknown tags are encoded structurally.
- A cycle, a reused index, or an index that is not reachable is invalid_input. Depth above 8, more than 32 nodes, more than 256 encoded bytes, or more than 512 hex characters in one content_hex is limit_exceeded.
- Disclaimer: format transform only; provides no confidentiality, integrity, or authenticity.

## Input

- `nodes` (array of object, required): min items 1; max items 32

## Output

- `der_hex` (string, required): min length 4; max length 512; pattern `^([0-9a-f]{2})+$`
- `byte_length` (integer, required): min 2; max 256
- `node_count` (integer, required): min 1; max 32

## Limits

- max der bytes: 256
- max depth: 8
- max nodes: 32
- max output bytes: 16384
- max tag decimal digits: 600
- max hex chars: 512

## Example

Request input:

```json
{
  "nodes": [
    {
      "tag_class": "universal",
      "tag_number": "9",
      "constructed": false,
      "content_hex": "",
      "child_indexes": []
    }
  ]
}
```

Response:

```json
{
  "result": {
    "der_hex": "0900",
    "byte_length": 2,
    "node_count": 1
  }
}
```

## How to call it

### MCP

Connect `https://computefirst.net/mcp` ([setup](/docs#connect)), then call `execute` with:

```json
{
  "id": "asn1-der-encode-tree",
  "version": "1.0.0",
  "input": {
    "nodes": [
      {
        "tag_class": "universal",
        "tag_number": "9",
        "constructed": false,
        "content_hex": "",
        "child_indexes": []
      }
    ]
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/asn1-der-encode-tree/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"nodes":[{"tag_class":"universal","tag_number":"9","constructed":false,"content_hex":"","child_indexes":[]}]}'
```

The machine-readable contract is at [/v1/tools/asn1-der-encode-tree/versions/1.0.0](/v1/tools/asn1-der-encode-tree/versions/1.0.0).

### CLI

```sh
node cli.mjs run asn1-der-encode-tree 1.0.0 --input input.json --base-url https://computefirst.net
```

Get the client at [/clients/cli/](/clients/cli/).

## Related tools

- [Asn1 der parse](/tools/asn1-der-parse): Parse one ASN.1 DER value into a flat schema-free TLV node list.
- [Asn1 der path list](/tools/asn1-der-path-list): List numeric paths, offsets, lengths, and tag class for every node in one DER value.
- [Asn1 der primitive encode](/tools/asn1-der-primitive-encode): Encode one universal DER primitive from typed fields into lowercase hex.
- [Asn1 der validate](/tools/asn1-der-validate): Check one ASN.1 DER value for canonical TLV structure and return a reason.
- [Asn1 der node extract](/tools/asn1-der-node-extract): Extract one DER node by a numeric path, with header, content, and child paths.
- [Asn1 der primitive decode](/tools/asn1-der-primitive-decode): Decode one universal DER primitive from lowercase hex into typed fields.
