Перейти к содержимому
Топаз6.0 · До релиза
Загрузка →

Поиск в документации

Спецификация 6.0

Выберите результат стрелками и нажмите Enter, чтобы открыть его.

Введите имя API, номер диагностики, правило или тему проекта.

    Библиотека · std.bytes

    Bytes.hmacSha256

    Uses this byte sequence as the key for an HMAC-SHA-256 computation.

    hmacSha256(message: Bytes) -> Bytes
    Модуль
    std.bytes →
    Получатель
    Bytes
    Минимальное число аргументов
    1
    Максимальное число аргументов
    1

    Declaration and parameters

    Ссылка

    Доступность

    Включено по умолчанию · Не определено

    Import std.bytes in language mode 5.21.

    The current compiler selects std/bytes.tpz for this language mode. Availability in other released editions and inclusion in each installed distribution are Pending.

    Получатель

    Bytes

    Ограничения параметров

    Bytes.crc32 returns the unsigned CRC-32/ISO-HDLC value as an int from 0 through 4294967295.

    CRC-32 uses width 32, polynomial 0x04c11db7, reflected input and output, initial value 0xffffffff, and final XOR 0xffffffff.

    Bytes.sha256 and Bytes.sha512 implement FIPS 180-4 and return 32 and 64 digest bytes respectively.

    Bytes.hmacSha256 uses its receiver as the key and its argument as the message. It returns the 32-byte HMAC-SHA-256 value from RFC 2104.

    HMAC hashes a key longer than the 64-byte SHA-256 block before zero-padding it. Empty keys and messages are valid.

    Empty input is valid for every checksum and digest. CRC-32 of empty input is zero.

    These operations process stored bytes without decoding or normalization. Inputs remain unchanged and correctly typed calls have no data-dependent failure.

    The receiver and any message argument evaluate once in that order. No external state, random input, or I/O affects the result.

    Use toHex or toBase64 on a digest when a text encoding is required. Those encodings are separate from the digest bytes.

    Результат

    The declared result type is Bytes.

    Эффекты

    Ошибки

    Result and effects

    Ссылка

    Use the receiver as the key and the argument as the message. Return the 32-byte HMAC-SHA-256 value.

    Resolved contracts

    Ссылка

    Related entries

    Ссылка

    std.bytes →

    Compute interoperable checksums and digests

    Ссылка
    Правилоtopaz.stdlib.contract.bytes-digests.rule

    Compute interoperable checksums and digests

    Bytes.crc32 returns the unsigned CRC-32/ISO-HDLC value as an int from 0 through 4294967295.

    CRC-32 uses width 32, polynomial 0x04c11db7, reflected input and output, initial value 0xffffffff, and final XOR 0xffffffff.

    Bytes.sha256 and Bytes.sha512 implement FIPS 180-4 and return 32 and 64 digest bytes respectively.

    Bytes.hmacSha256 uses its receiver as the key and its argument as the message. It returns the 32-byte HMAC-SHA-256 value from RFC 2104.

    HMAC hashes a key longer than the 64-byte SHA-256 block before zero-padding it. Empty keys and messages are valid.

    Empty input is valid for every checksum and digest. CRC-32 of empty input is zero.

    These operations process stored bytes without decoding or normalization. Inputs remain unchanged and correctly typed calls have no data-dependent failure.

    The receiver and any message argument evaluate once in that order. No external state, random input, or I/O affects the result.

    Use toHex or toBase64 on a digest when a text encoding is required. Those encodings are separate from the digest bytes.

    Причина

    Named standard algorithms must agree with independent implementations. Keeping digest bytes separate from their text representation makes the same digest usable in binary and text formats.

    Match established checksum and hash vectors

    Ссылка
    main.tpzMatch established checksum and hash vectorsОткрыть песочницу →
    1. import std.bytes { Bytes }
    2. import std.io
    3. io.writeLine("{Bytes.empty().crc32()}")
    4. let checksum = "123456789".encodeUtf8().crc32()
    5. io.writeLine("{checksum}")
    6. io.writeLine("abc".encodeUtf8().sha256().toHex())
    7. io.writeLine("abc".encodeUtf8().sha512().toHex())
    8. io.writeLine("key".encodeUtf8().hmacSha256("The quick brown fox jumps over the lazy dog".encodeUtf8()).toHex())
    Ожидаемый выводКод завершения 0
    0
    3421780262
    ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad
    ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f
    f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8
    
    $ topaz run main.tpz · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Выполнение завершается. Код завершения 0.

    Ожидаемый стандартный вывод
    1. 0
    2. 3421780262
    3. ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad
    4. ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f
    5. f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8

    Меню

    Загрузка →