Crate actix_plus_utils[][src]

Overview

This crate simply provides various miscellaneous utilities that are useful in the course of actix-web development, like a function to sanitize control characters from a string (commonly used in user input). See the docs.rs documentation for a complete list of currently available functions.

License

Dual licenced under MIT or Apache-2.0 license, the same license as actix-web.

Functions

current_unix_time_secs

Returns the current unix time in seconds. This is useful both for when working with external APIs or libraries that expect a UNIX time, and for cleanly keeping track of time in one’s own code.

secure_random_string

Generates a secure random string. This is useful for token generation, such as email verification tokens. This string can contain any of the characters in the string “abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890” with equal probability.

validate_and_sanitize_string

Validates a given string to contain only text characters (from any language), and no control characters, thus making it safe to display in a web page IF IT IS THEN PROPERLY ESCAPED, AS AN ADDITIONAL STEP. THIS METHOD DOES NOT ESCAPE FOR HTML, JAVASCRIPT, OR ANY OTHER LANGUAGE. If allow_new_line is set to true, then \n and \r are allowed, but \r is removed. If a string contains control characters (other than \n and \r when allow_new_line is true) then a ResponseResult that allows 400 Bad Request to be propagated is returned. If you prefer to use your own error handling, you can simply match on the Err variant and interpret as documented here.