Giter Club home page Giter Club logo

sexp's Introduction

S-expressions parser and generator library in C++ (SEXP in C++)

Build status Ubuntu/macOS/Windows Build status CentOS/Fedora Build status Debian Build status MSys

Code coverage CodeQL analysis Coverity Scan Build Status

Purpose

This is a C++ library for working with S-expressions. This implementation is derived from the reference SEXP C library developed by Professors Ronald Rivest and Butler Lampson of MIT LCS (now CSAIL).

This library differs from the original C implementation in the following ways:

  • It aims to be reuseable in C++ implementations and is importable via CMake.

  • It includes a test suite for correctness testing and tests against malformed S-expressions.

  • It supports, and is tested against, all major platforms, including:

    • Ubuntu, Debian, Fedora, CentOS

    • macOS

    • Windows

    • msys

  • It implements additional interface to work with S-expressions wrapped by GnuPG 2.3+ extended format as defined at https://github.com/gpg/gnupg/blob/master/agent/keyformat.txt

The original C library is available at:

Background

S-expressions are a data structure for representing complex data as a variation on LISP S-expressions.

S-expressions were originally adopted for use in SDSI and SPKI.

SDSI has been developed by Professors Ronald L. Rivest and Butler Lampson of MIT’s Laboratory for Computer Science, members of LCS’s Cryptography and Information Security research group.

Note
SDSI research has been supported by DARPA contract DABT63-96-C-0018, "Security for Distributed Computer Systems".
Note
SPKI has been developed by Carl Ellison and others in the IETF SPKI working group.

Usage guide for S-expressions

Code

The library is a deep rework to C++ of the original SEXP library that maintains full support of original specification.

While most applications will not need anything but the simple canonical and transport formats; however, the code here is considerably more complex because it also supports the advanced format, both for input and for output.

Building and installation

mkdir build
cd build
cmake ..
cmake --build .
ctest
cmake --install .

CMake script options

WITH_SEXP_TESTS:BOOL

build tests (default: ON)

DOWNLOAD_GTEST

if tests are build download googletest from github (default: ON) when this option is set to OFF googletest binary package is a prerequisite for SEXP tests

WITH_SEXP_CLI:BOOL

build the sexp client application (default: ON)

WITH_SANITIZERS:BOOL

build with address and other sanitizers (default: OFF) (requires clang compiler)

SEXP command-line utility

The sexp command-line utility is reference parser and generator of S-expressions. It can read, parse and print out SEXP in all defined formats.

sexp switches:

Switch Description Default

Input

-i <filename>

input file name

read input from console (stdin)

-p

prompt input if reading from console

disabled

-s

treat input as a single SEXP string

disabled, input is treated as S-expression

Output

-o <filename>

output file name:

write output to console (stdout)

-a

generate advanced transport format

enabled if no format is specified

-b

generate base-64 transport format

disabled

-c

generate canonical format

disabled

-l

suppress linefeeds after output

disabled

-w <width>

set output line width (0 implies no constraint)

75

Miscellaneous

-x

execute repeatedly until EOF

process single S-expression then exit

-h

print help message and exit

Running without switches implies: -p -a -b -c -x

Usage examples:

Prompt for S-expressions input from console, parse and output it to certificate.dat in base64 transport format

sexp -o certificate.dat -p -b

> Input:
> (aa bb (cc dd))
>
> Writing base64 (of canonical) output to 'certificate.dat'

Parse all S-expressions from certificate.dat, output them to console in advanced transport format with no prompts

sexp -i certificate.dat -x

> (2:aa2:bb(2:cc2:dd))

Parse S-expressions from certificate.dat, output it to console in canonical, base64 and advanced format with prompts and no width limitation

sexp -i certificate.dat -a -b -c -p -w 0

> Reading input from certificate.dat
>
> Canonical output:
> (2:aa2:bb(2:cc2:dd))
> Base64 (of canonical) output:
> {KDI6YWEyOmJiKDI6Y2MyOmRkKSk=}
> Advanced transport output:
> (aa bb (cc dd))

Repeatedly prompt for S-expressions input from console, parse and output it console in advanced, base64 and canonical formats

sexp -p -a -b -c -x

or just

sexp

> Input:
> (abc def (ghi jkl))
>
> Canonical output:
> (3:abc3:def(3:ghi3:jkl))
> Base64 (of canonical) output:
> {KDM6YWJjMzpkZWYoMzpnaGkzOmprbCkp}
> Advanced transport output:
> (abc def (ghi jkl))
>
> Input:
> ^C

License

The code is made available as open-source software under the MIT License.

sexp's People

Contributors

maxirmx avatar ronaldtse avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.