Git Product home page Git Product logo

c14n's Introduction

c14n

go.dev reference GitHub Workflow Status

This package is a Golang implementation of XML Canonicalization ("c14n"). In particular, it implements the Exclusive Canonical XML specification, which is the recommended canonicalization scheme used in SAML.

If you're looking to canonicalize XML because you're implementing SAML or XML Digital Signature, consider using github.com/ucarion/saml or github.com/ucarion/dsig, which are implemented using this package.

Installation

Install this package by running:

go get github.com/ucarion/c14n

Usage

The most common way to use this package is to call c14n.Canonicalize with a xml.Decoder:

input := `<foo z="2" a="1"><bar /></foo>`
decoder := xml.NewDecoder(strings.NewReader(input))
out, err := c14n.Canonicalize(decoder)
fmt.Println(string(out), err)
// Output:
// <foo a="1" z="2"><bar></bar></foo> <nil>

Limitations

This package ignores processing directives, and so technically does not fully comply with the Exclusive Canonical XML spec. In particular, the spec says that if you have a document like this:

<!DOCTYPE doc [
<!ENTITY ent1 "Hello">
<!ENTITY ent2 SYSTEM "world.txt">
]>
<doc attrExtEnt="entExt">
   &ent1;, &ent2;!
</doc>

<!-- Assume world.txt contains "world" (excluding the quotes) -->

Then it should be canonicalized as:

<doc attrExtEnt="entExt">
   Hello, world!
</doc>

But in order to do that, this package would need to potentially do I/O in order to work, and it would need to understand the entire DTD spec. Furthermore, the standard library's XML decoder doesn't support parsing custom entities (instead, it errors out), so this package would need to ship an alternative to xml.Decoder.

Thus, this package does not support custom entities and other features driven by processing directives. In practice, these features are rarely used in common protocols like SAML.

c14n's People

Contributors

ucarion avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  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.