Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Gleam language #5706

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,9 @@
[submodule "vendor/grammars/vscode-gedcom"]
path = vendor/grammars/vscode-gedcom
url = https://github.com/fguitton/vscode-gedcom
[submodule "vendor/grammars/vscode-gleam"]
path = vendor/grammars/vscode-gleam
url = https://github.com/gleam-lang/vscode-gleam.git
[submodule "vendor/grammars/vscode-go"]
path = vendor/grammars/vscode-go
url = https://github.com/golang/vscode-go
Expand Down
2 changes: 2 additions & 0 deletions grammars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,8 @@ vendor/grammars/vscode-gcode-syntax:
- source.gcode
vendor/grammars/vscode-gedcom:
- source.gedcom
vendor/grammars/vscode-gleam:
- source.gleam
vendor/grammars/vscode-go:
- go.mod
- go.sum
Expand Down
10 changes: 10 additions & 0 deletions lib/linguist/languages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1888,6 +1888,16 @@ GEDCOM:
- ".ged"
tm_scope: source.gedcom
language_id: 459577965
Gleam:
type: programming
color: "#FFAFF3"
extensions:
- ".gleam"
tm_scope: source.gleam
ace_mode: text
codemirror_mode: clike
codemirror_mime_type: text/x-gleam
language_id: 1054258749
GLSL:
type: programming
color: "#5686a5"
Expand Down
67 changes: 67 additions & 0 deletions samples/Gleam/crypto.gleam
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Taken from https://github.com/gleam-experiments/crypto
// Apache-2.0 licensed

//// Set of cryptographic functions.

import gleam/bit_string.{BitString}
import gleam/bitwise

/// Generates N bytes randomly uniform 0..255, and returns the result in a binary.
///
/// Uses a cryptographically secure prng seeded and periodically mixed with operating system provided entropy.
/// By default this is the RAND_bytes method from OpenSSL.
///
/// https://erlang.org/doc/man/crypto.html#strong_rand_bytes-1
pub external fn strong_random_bytes(Int) -> BitString =
"crypto" "strong_rand_bytes"

pub type HashAlgorithm {
Sha224
Sha256
Sha384
Sha512
}

// Just take BitString while Iodata has semantics of Strings
//
/// Computes a digest of the input binary.
pub external fn hash(HashAlgorithm, BitString) -> BitString =
"crypto" "hash"

type Hmac {
Hmac
}

external fn erl_hmac(Hmac, HashAlgorithm, BitString, BitString) -> BitString =
"crypto" "mac"

pub fn hmac(data: BitString, algorithm: HashAlgorithm, key: BitString) {
erl_hmac(Hmac, algorithm, key, data)
}

fn do_secure_compare(left, right, accumulator) {
case left, right {
[x, ..left], [y, ..right] -> {
let accumulator = bitwise.or(accumulator, bitwise.exclusive_or(x, y))
do_secure_compare(left, right, accumulator)
}
[], [] -> accumulator == 0
}
}

external fn binary_to_list(BitString) -> List(Int) =
"erlang" "binary_to_list"

/// Compares the two binaries in constant-time to avoid timing attacks.
///
/// For more details see: http://codahale.com/a-lesson-in-timing-attacks/
pub fn secure_compare(left: BitString, right: BitString) {
case bit_string.byte_size(left) == bit_string.byte_size(right) {
True -> {
let left = binary_to_list(left)
let right = binary_to_list(right)
do_secure_compare(left, right, 0)
}
False -> False
}
}
Loading