From 38cb7aae0959e230026fd26318a1dcb3342308b8 Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Tue, 15 Aug 2017 10:55:04 +0200 Subject: [PATCH] Move base64 algorithms to Infra See https://github.com/whatwg/infra/pull/145 for the change to the Infra Standard. Closes #2912. --- source | 198 ++++----------------------------------------------------- 1 file changed, 11 insertions(+), 187 deletions(-) diff --git a/source b/source index 4bb06f05002..c0cf8b7c273 100644 --- a/source +++ b/source @@ -143,24 +143,6 @@ .parse-error-table td > p:first-child { margin-top: 0; } - #base64-table { - white-space: nowrap; - font-size: 0.6em; - column-width: 6em; - column-count: 5; - column-gap: 1em; - -moz-column-width: 6em; - -moz-column-count: 5; - -moz-column-gap: 1em; - -webkit-column-width: 6em; - -webkit-column-count: 5; - -webkit-column-gap: 1em; - } - #base64-table thead { display: none; } - #base64-table * { border: none; } - #base64-table tbody td:first-child:after { content: ':'; } - #base64-table tbody td:last-child { text-align: right; } - #named-character-references-table { white-space: nowrap; font-size: 0.6em; @@ -2450,6 +2432,8 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute append
  • The struct specification type and the associated definition for item
  • +
  • The forgiving-base64 encode and + forgiving-base64 decode algorithms
  • HTML namespace
  • MathML namespace
  • SVG namespace
  • @@ -90025,7 +90009,7 @@ interface WindowOrWorkerGlobalScope { // base64 utility methods DOMString btoa(DOMString data); - DOMString atob(DOMString data); + ByteString atob(DOMString data); // timers long setTimeout(TimerHandler handler, optional long timeout = 0, any... arguments); @@ -90114,180 +90098,23 @@ document.body.appendChild(frame)

    The btoa(data) method must throw an "InvalidCharacterError" DOMException if data contains any character whose code point is greater than U+00FF. Otherwise, the - user agent must convert data to a sequence of octets whose nth octet is the - eight-bit representation of the code point of the nth character of data, and - then must apply the base64 algorithm to that sequence of octets, and return the result.

    - - + user agent must convert data to a byte sequence whose nth byte is the + eight-bit representation of the nth code point of data, and then must apply + forgiving-base64 encode to that byte sequence and return the result.

    The atob(data) method, when invoked, must run the following steps:

      +
    1. Let decodedData be the result of running forgiving-base64 decode + on data.

    2. - - - - -
    3. Let position be a pointer into data, initially - pointing at the start of the string.

    4. - -
    5. Remove all ASCII whitespace from data.

    6. - -
    7. If the length of data divides by 4 leaving no remainder, then: if - data ends with one or two U+003D EQUALS SIGN (=) characters, remove them from - data.

    8. - -
    9. If the length of data divides by 4 leaving a remainder of 1, throw an - "InvalidCharacterError" DOMException and abort these - steps.

      - -
    10. - -

      If data contains a character that is not in the following list of - characters and character ranges, throw an "InvalidCharacterError" - DOMException and abort these steps:

      - -
        -
      • U+002B PLUS SIGN (+) -
      • U+002F SOLIDUS (/) -
      • ASCII alphanumeric -
      - -
    11. - -
    12. Let output be a string, initially empty.

    13. - -
    14. Let buffer be a buffer that can have bits appended to it, initially - empty.

    15. - -
    16. - -

      While position does not point past the end of data, run these - substeps:

      - -
        - -
      1. - -

        Find the character pointed to by position in the first column of the - following table. Let n be the number given in the second cell of the same - row.

        - -
        - - - - -
        Character - Number -
        A0 -
        B1 -
        C2 -
        D3 -
        E4 -
        F5 -
        G6 -
        H7 -
        I8 -
        J9 -
        K10 -
        L11 -
        M12 -
        N13 -
        O14 -
        P15 -
        Q16 -
        R17 -
        S18 -
        T19 -
        U20 -
        V21 -
        W22 -
        X23 -
        Y24 -
        Z25 -
        a26 -
        b27 -
        c28 -
        d29 -
        e30 -
        f31 -
        g32 -
        h33 -
        i34 -
        j35 -
        k36 -
        l37 -
        m38 -
        n39 -
        o40 -
        p41 -
        q42 -
        r43 -
        s44 -
        t45 -
        u46 -
        v47 -
        w48 -
        x49 -
        y50 -
        z51 -
        052 -
        153 -
        254 -
        355 -
        456 -
        557 -
        658 -
        759 -
        860 -
        961 -
        +62 -
        /63 -
        -
        - -
      2. - -
      3. Append to buffer the six bits corresponding to number, most significant bit first.

      4. - -
      5. If buffer has accumulated 24 bits, interpret them as three 8-bit - big-endian numbers. Append the three characters with code points equal to those numbers to output, in the same order, and then empty buffer.

      6. - -
      7. Advance position by one character.

      8. - -
      - -
    17. - -
    18. - -

      If buffer is not empty, it contains either 12 or 18 bits. If it contains - 12 bits, discard the last four and interpret the remaining eight as an 8-bit big-endian number. - If it contains 18 bits, discard the last two and interpret the remaining 16 as two 8-bit - big-endian numbers. Append the one or two characters with code points equal to those one or two - numbers to output, in the same order.

      - -

      The discarded bits mean that, for instance, atob("YQ") and - atob("YR") both return "a".

      - -
    19. - -
    20. Return output.

    21. +
    22. If decodedData is failure, then throw an + "InvalidCharacterError" DOMException.

    23. +
    24. Return decodedData.

    - - @@ -120244,9 +120071,6 @@ INSERT INTERFACES HERE
    [RFC7595]
    Guidelines and Registration Procedures for URI Schemes, D. Thaler, T. Hansen, T. Hardie. IETF.
    -
    [RFC4648]
    -
    The Base16, Base32, and Base64 Data Encodings, S. Josefsson. IETF.
    -
    [RFC5322]
    Internet Message Format, P. Resnick. IETF.