Skip to content

Commit

Permalink
ci: add GitHub Actions workflow for Rust build and tests
Browse files Browse the repository at this point in the history
This commit introduces a new GitHub Actions workflow to automate the
Rust build and testing process. The workflow triggers on pushes and pull
requests to the "main" branch. It ensures that the Rust project is built
and all tests are run using the latest Ubuntu environment.

This automation improves the CI pipeline by catching build or test
issues early during development.
  • Loading branch information
pycckuu committed Sep 27, 2024
1 parent 15d4222 commit 13cd10f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Rust

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

env:
CARGO_TERM_COLOR: always

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
22 changes: 10 additions & 12 deletions src/ec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ pub struct EllipticCurve {
}

impl EllipticCurve {
pub fn new(a: BigUint, b: BigUint, p: BigUint) -> Self {
EllipticCurve { a, b, p }
}

pub fn add(&self, p1: &Point, p2: &Point) -> Point {
match (p1, p2) {
(Point::Identity, _) => p2.clone(),
Expand Down Expand Up @@ -102,7 +98,7 @@ impl EllipticCurve {
let mut temp = p.clone();
let mut n = scalar.clone();

while n != BigUint::from(0u32) {
while n > BigUint::from(0u32) {
if n.bit(0) {
result = self.add(&result, &temp);
}
Expand Down Expand Up @@ -132,11 +128,11 @@ mod tests {
use super::*;

fn create_test_curve() -> EllipticCurve {
EllipticCurve::new(
BigUint::from(2u32),
BigUint::from(2u32),
BigUint::from(17u32),
)
EllipticCurve {
a: BigUint::from(2u32),
b: BigUint::from(2u32),
p: BigUint::from(17u32),
}
}

mod point_operations {
Expand All @@ -159,7 +155,10 @@ mod tests {

assert_eq!(curve.add(&Point::Identity, &p), p);
assert_eq!(curve.add(&p, &Point::Identity), p);
assert_eq!(curve.add(&Point::Identity, &Point::Identity), Point::Identity);
assert_eq!(
curve.add(&Point::Identity, &Point::Identity),
Point::Identity
);
}

#[test]
Expand Down Expand Up @@ -209,5 +208,4 @@ mod tests {
assert!(!curve.is_on_curve(&not_on_curve));
}
}

}

0 comments on commit 13cd10f

Please sign in to comment.