-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#464 Remove usage 'radix_encoding' since it has too many transitive d…
…ependencies
- Loading branch information
Showing
5 changed files
with
37 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module Asciidoctor | ||
module Diagram | ||
module Base64 | ||
def self.urlsafe_encode(bin, padding: true) | ||
str = [bin].pack("m0") | ||
str.chomp!("==") or str.chomp!("=") unless padding | ||
str.tr!("+/", "-_") | ||
str | ||
end | ||
|
||
def self.urlsafe_decode(str) | ||
# NOTE: RFC 4648 does say nothing about unpadded input, but says that | ||
# "the excess pad characters MAY also be ignored", so it is inferred that | ||
# unpadded input is also acceptable. | ||
if !str.end_with?("=") && str.length % 4 != 0 | ||
str = str.ljust((str.length + 3) & ~3, "=") | ||
str.tr!("-_", "+/") | ||
else | ||
str = str.tr("-_", "+/") | ||
end | ||
str.unpack1("m0") | ||
end | ||
end | ||
end | ||
end |