GithubHelp home page GithubHelp logo

my-01-rcli's Introduction

Geektime Rust 语言训练营

作业

目录展示

server start

 cargo run http server  

作业,目录展示

http://127.0.0.1:8080/dir/fixtures

chacha20 加密,解密

作业,生成key,会在fixture下生成: ChaCha20Poly1305.txt

cargo run text chip-generate --output-path ./fixtures

加密测试,控制台会输出加密后的base64字符,./fixtures/nonce.txt是nonce

cargo run text encrypt --key ./fixtures/ChaCha20Poly1305.txt --nonce-output-path ./fixtures  --input ./fixtures/chacha20input.text

解密测试,控制台会输出解密后的base64字符,./fixtures/nonce.txt是上次加密的nonce

cargo run text decrypt --key ./fixtures/ChaCha20Poly1305.txt --nonce-input-path ./fixtures/nonce.txt

jwt 加密解密

数据结构定义,输入的内容,自动放到data字段,exp是unix时间戳,标识过期时间

{"data":"hello world","exp":1715677104}

加密,参数 --exp 暂时只支持天单位,比如:1d

cargo run jwt encode --data "hello world"  --secret ./fixtures/jwt_secret.txt --exp 1d

解密,其中data 值是前面加密打印的值

cargo run jwt decode --data eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJkYXRhIjoiaGVsbG8gd29ybGQiLCJleHAiOjE3MTU2Nzg0MjV9.j9mcf65yIGwkqtTreIr_Km3f-_xB7VWmJdT7yH4YL8s  --secret ./fixtures/jwt_secret.txt

验证jwt

cargo run jwt verify --data eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJkYXRhIjoiaGVsbG8gd29ybGQiLCJleHAiOjE3MTU3NjMwMjh9.YE-4ZBDj5QnvxwCC7F2i_UkbWvHcMYxSoQ1-Hs3u0is --secret ./fixtures/jwt_secret.txt

img.png

环境设置

安装 Rust

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

安装 VSCode 插件

  • crates: Rust 包管理
  • Even Better TOML: TOML 文件支持
  • Better Comments: 优化注释显示
  • Error Lens: 错误提示优化
  • GitLens: Git 增强
  • Github Copilot: 代码提示
  • indent-rainbow: 缩进显示优化
  • Prettier - Code formatter: 代码格式化
  • REST client: REST API 调试
  • rust-analyzer: Rust 语言支持
  • Rust Test lens: Rust 测试支持
  • Rust Test Explorer: Rust 测试概览
  • TODO Highlight: TODO 高亮
  • vscode-icons: 图标优化
  • YAML: YAML 文件支持

安装 cargo generate

cargo generate 是一个用于生成项目模板的工具。它可以使用已有的 github repo 作为模版生成新的项目。

cargo install cargo-generate

在我们的课程中,新的项目会使用 tyr-rust-bootcamp/template 模版生成基本的代码:

cargo generate tyr-rust-bootcamp/template

安装 pre-commit

pre-commit 是一个代码检查工具,可以在提交代码前进行代码检查。

pipx install pre-commit

安装成功后运行 pre-commit install 即可。

安装 Cargo deny

Cargo deny 是一个 Cargo 插件,可以用于检查依赖的安全性。

cargo install --locked cargo-deny

安装 typos

typos 是一个拼写检查工具。

cargo install typos-cli

安装 git cliff

git cliff 是一个生成 changelog 的工具。

cargo install git-cliff

安装 cargo nextest

cargo nextest 是一个 Rust 增强测试工具。

cargo install cargo-nextest --locked

my-01-rcli's People

Contributors

soddygo avatar songguochao avatar

Watchers

 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.