#### BAS

#### Synopsis

    HELP:   Convert Base16/32/64/85 encoded data to binary data
    TYPE:   OBJECT
    SYNTAX: BAS(BUFSIZ=num,RECCNT=num,RECLEN=num,METHOD=BASE16/BASE32/BASE64,MODE=BLOCK/RECORD,CHRSET=NONE/SYSTEM/ASCII/UCS1/UTF8/EBCDIC/UCS2BE/UTF16BE/UCS2LE/UTF16LE/UCS4BE/UTF32BE/UCS4LE/UTF32LE/LOCAL,CRCCHK,ARMCHK,RSTCHK,SKPNOB,TARGET=PGP/CRY/ZIP/BIN/CHR/TXT/XML)

#### Description

The base converter can be used to convert data from binary format to printable text and vice versa using one of a couple of base encoding schemes (RFC 4648). When writing, binary data is encoded, when reading, encoded text is decoded. Encoding data to a different base results in expansion of the data. The ratio of expansion depends on the base used.

Most base encoding schemes append some padding bytes to the end of output data to pad it to a multiple of a specific length. As a result, encoding and decoding can be performed in one of two modes:

The block mode converts the input data as one large block of binary data. Padding will only be added at the end of the output file. This mode is the default for any type of input data, unless specified otherwise. This implies that record-based data will not retain record boundaries after encoding. As the output is printable text when encoding, it can optionally be split into multiple lines. The 'line' length parameter specifies after how many characters a line is wrapped. The line delimiter can be configured, but can also be omitted, which is useful to write the output record-oriented. When writing record-oriented, each output line results in one record. Note that if the 'line' length parameter is specified and a line delimiter is set, then the total maximum record length will be line length plus the length of the delimiter.

The record mode can be useful if the input data is record-based. In record mode, each record is encoded independently, which results in retaining the ability to access specific records by only decoding those specific records. Each output record is padded as required by the respective encoding scheme. Due to base encoding resulting in expansion of the data, the resulting records will be longer after encoding and shrink when decoding. To read a file that has been encoded in record mode, setting mode=record is mandatory. Otherwise, the result might be garbage.

The character set used (ASCII or EBCDIC) can also be configured. By default, the system-specific character set is used.

Mainly for PGP support, the component supports optional ASCII armor (also in EBCDIC) headers and trailers around the base encoded data (see RFC4880), but can also be used for other data and is independent of the encoding method (Base16/32/64). ASCII-armored data data is wrapped into lines, which can be written as records or as blocks with lines and delimiters. The default line length is 72 if no length is specified. When reading, the trailer string can optionally be verified to match the header string.

Another feature for OpenPGP support is a CRC checksum that is appended to the data. This is also optional and usable independently of the data, the encoding schema and the ASCII armor support. When writing, a switch can be enabled to add a CRC24 checksum conforming to RCF4880 for Base64 encodings. The other encoding schemas use the same mechanism to append a checksum to the base encoded data, but use another CRC variant. Base16 uses CRC32 and Base32 uses CRC40, known from the GSM network. When reading, a switch enables verification of this checksum. By default, no CRC verification is done. Since the checksum is optional, it is useless to calculate the CRC just to find out that there is no CRC appended to the data that can be compared against. If the verification fails, you get an error. If the verification is successful, you get an informational. If there is no checksum appended for verification, you get a warning. The same is true if verification is not requested, but a checksum is found.

With the TARGET selection you can limit the valid target formats after base decoding. For example, this can be used to ensure, that a base decoding is only done, if the result XML or a PGP message or a compressed data stream.

#### Arguments

- `NUMBER: BUFSIZ=num - Initial buffer size for preallocation [65536]`
- `NUMBER: RECCNT=num - Initial amount of records for preallocation [128]`
- `NUMBER: RECLEN=num - Record length to parse ASCII Armor without delimiter`
- `NUMBER: METHOD=BASE16/BASE32/BASE64 - Base encoding selector [AUTO]`
  - `BASE16 - Base16 (hexadecimal) encoding`
  - `BASE32 - Base32 encoding`
  - `BASE64 - Base64 encoding`
- `NUMBER: MODE=BLOCK/RECORD - Enforces record or block-oriented conversion [BLOCK]`
  - `BLOCK - Block-oriented conversion (all data is one chunk)`
  - `RECORD - Record-oriented conversion (convert each record individually)`
- `NUMBER: CHRSET=NONE/SYSTEM/ASCII/UCS1/UTF8/EBCDIC/UCS2BE/UTF16BE/UCS2LE/UTF16LE/UCS4BE/UTF32BE/UCS4LE/UTF32LE/LOCAL - Character set [SYSTEM]`
  - `NONE - No character set defined`
  - `SYSTEM - SYSTEM (environment specific (on mainframe EBCDIC else ASCII))`
  - `ASCII - ASCII (mainly used in the for open system)`
  - `UCS1 - UCS-1 (for text formatting identical to ASCII < 64k)`
  - `UTF8 - UTF-8 (for text formatting identical to ASCII < 2M)`
  - `EBCDIC - EBCDIC (mainly used on IBM mainframe)`
  - `UCS2BE - UCS-2 Big Endian (multibyte character set < 64k)`
  - `UTF16BE - UTF-16 Big Endian (multibyte character set < 2M)`
  - `UCS2LE - UCS-2 Little Endian (multibyte character set < 64k)`
  - `UTF16LE - UTF-16 Little Endian (multibyte character set < 2M)`
  - `UCS4BE - UCS-4 Big Endian (multibyte character set < 64k)`
  - `UTF32BE - UTF-32 Big Endian (multibyte character set < 2M)`
  - `UCS4LE - UCS-4 Little Endian (multibyte character set < 64k)`
  - `UTF32LE - UTF-32 Little Endian (multibyte character set < 2M)`
  - `LOCAL - LOCAL (platform specific (on mainframe EBCDIC else ASCII))`
- `SWITCH: CRCCHK - Check CRC if available [FALSE]`
- `SWITCH: ARMCHK - Check ARMOR trailer if available [FALSE]`
- `SWITCH: RSTCHK - Check if a rest after encoded data [FALSE]`
- `SWITCH: SKPNOB - Skip base decoding if no base encoding detected [FALSE]`
- `NUMBER: TARGET=PGP/CRY/ZIP/BIN/CHR/TXT/XML - Limit target format for base decoding [NONE]`
  - `PGP - PGP files (message, signature or key file)`
  - `CRY - Encrypted data stream (including PGP message)`
  - `ZIP - Compressed data stream (GZIP, BZIP2, XZ)`
  - `BIN - Binary data`
  - `CHR - Character data`
  - `TXT - Text data`
  - `XML - XML data`