| 1 | package rardecodescip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/ |
| 2 | |
| 3 | import ( |
| 4 | "crypto/aesscip-go gomod github.com/golang/go/src go1.21 `crypto/aes`/" |
| 5 | "crypto/cipherscip-go gomod github.com/golang/go/src go1.21 `crypto/cipher`/" |
| 6 | "ioscip-go gomod github.com/golang/go/src go1.21 io/" |
| 7 | ) |
| 8 | |
| 9 | // cipherBlockReader implements Block Mode decryption of an io.Reader object. |
| 10 | type cipherBlockReaderscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader# struct { |
| 11 | brscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#br. byteReaderscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/byteReader# |
| 12 | modescip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#mode. cipherscip-go gomod github.com/golang/go/src go1.21 `crypto/cipher`/.BlockModescip-go gomod github.com/golang/go/src go1.21 `crypto/cipher`/BlockMode# |
| 13 | inbufscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#inbuf. []byte // raw input blocks not yet decrypted |
| 14 | outbufscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#outbuf. []byte // output buffer used when output slice < block size |
| 15 | blockscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#block. []byte // input/output buffer for a single block |
| 16 | } |
| 17 | |
| 18 | func (cr *cipherBlockReaderscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#) fillOutbufscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#fillOutbuf().() error { |
| 19 | l := len(cr.inbufscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#inbuf.) |
| 20 | _, err := ioscip-go gomod github.com/golang/go/src go1.21 io/.ReadFullscip-go gomod github.com/golang/go/src go1.21 io/ReadFull().(cr.brscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#br., cr.blockscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#block.[l:]) |
| 21 | if err != nil { |
| 22 | return err |
| 23 | } |
| 24 | cr.modescip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#mode..CryptBlocksscip-go gomod github.com/golang/go/src go1.21 `crypto/cipher`/BlockMode#CryptBlocks().(cr.blockscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#block., cr.blockscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#block.) |
| 25 | cr.outbufscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#outbuf. = cr.blockscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#block. |
| 26 | return nil |
| 27 | } |
| 28 | |
| 29 | func (cr *cipherBlockReaderscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#) ReadBytescip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#ReadByte().() (byte, error) { |
| 30 | if len(cr.outbufscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#outbuf.) == 0 { |
| 31 | err := cr.fillOutbufscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#fillOutbuf().() |
| 32 | if err != nil { |
| 33 | return 0, err |
| 34 | } |
| 35 | } |
| 36 | b := cr.outbufscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#outbuf.[0] |
| 37 | cr.outbufscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#outbuf. = cr.outbufscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#outbuf.[1:] |
| 38 | return b, nil |
| 39 | } |
| 40 | |
| 41 | // Read reads and decrypts data into p. |
| 42 | // If the input is not a multiple of the cipher block size, |
| 43 | // the trailing bytes will be ignored. |
| 44 | func (cr *cipherBlockReaderscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#) Readscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#Read().(p []byte) (int, error) { |
| 45 | if len(cr.outbufscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#outbuf.) > 0 { |
| 46 | n := copy(p, cr.outbufscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#outbuf.) |
| 47 | cr.outbufscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#outbuf. = cr.outbufscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#outbuf.[n:] |
| 48 | return n, nil |
| 49 | } |
| 50 | blockSize := cr.modescip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#mode..BlockSizescip-go gomod github.com/golang/go/src go1.21 `crypto/cipher`/BlockMode#BlockSize().() |
| 51 | if len(p) < blockSize { |
| 52 | // use cr.block as buffer |
| 53 | err := cr.fillOutbufscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#fillOutbuf().() |
| 54 | if err != nil { |
| 55 | return 0, err |
| 56 | } |
| 57 | n := copy(p, cr.outbufscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#outbuf.) |
| 58 | cr.outbufscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#outbuf. = cr.outbufscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#outbuf.[n:] |
| 59 | return n, nil |
| 60 | } |
| 61 | // use p as buffer (but round down to multiple of block size) |
| 62 | p = p[:len(p)-(len(p)%blockSize)] |
| 63 | l := len(cr.inbufscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#inbuf.) |
| 64 | if l > 0 { |
| 65 | copy(p, cr.inbufscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#inbuf.) |
| 66 | cr.inbufscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#inbuf. = nil |
| 67 | } |
| 68 | n, err := ioscip-go gomod github.com/golang/go/src go1.21 io/.ReadAtLeastscip-go gomod github.com/golang/go/src go1.21 io/ReadAtLeast().(cr.brscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#br., p[l:], blockSize-l) |
| 69 | if err != nil { |
| 70 | return 0, err |
| 71 | } |
| 72 | n += l |
| 73 | p = p[:n] |
| 74 | n -= n % blockSize |
| 75 | if n != len(p) { |
| 76 | l = copy(cr.blockscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#block., p[n:]) |
| 77 | cr.inbufscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#inbuf. = cr.blockscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#block.[:l] |
| 78 | p = p[:n] |
| 79 | } |
| 80 | cr.modescip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#mode..CryptBlocksscip-go gomod github.com/golang/go/src go1.21 `crypto/cipher`/BlockMode#CryptBlocks().(p, p) |
| 81 | return n, nil |
| 82 | } |
| 83 | |
| 84 | func (cr *cipherBlockReaderscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#) writeToNscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#writeToN().(w ioscip-go gomod github.com/golang/go/src go1.21 io/.Writerscip-go gomod github.com/golang/go/src go1.21 io/Writer#, n int64) (int64, error) { |
| 85 | if n == 0 { |
| 86 | return 0, nil |
| 87 | } |
| 88 | var tot int64 |
| 89 | var err error |
| 90 | for tot != n && err == nil { |
| 91 | if len(cr.outbufscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#outbuf.) == 0 { |
| 92 | err = cr.fillOutbufscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#fillOutbuf().() |
| 93 | if err != nil { |
| 94 | break |
| 95 | } |
| 96 | } |
| 97 | buf := cr.outbufscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#outbuf. |
| 98 | if n > 0 { |
| 99 | todo := n - tot |
| 100 | if todo < int64(len(buf)) { |
| 101 | buf = buf[:todo] |
| 102 | } |
| 103 | } |
| 104 | var l int |
| 105 | l, err = w.Writescip-go gomod github.com/golang/go/src go1.21 io/Writer#Write().(buf) |
| 106 | tot += int64(l) |
| 107 | cr.outbufscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#outbuf. = cr.outbufscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#outbuf.[l:] |
| 108 | } |
| 109 | if n < 0 && err == ioscip-go gomod github.com/golang/go/src go1.21 io/.EOFscip-go gomod github.com/golang/go/src go1.21 io/EOF. { |
| 110 | err = nil |
| 111 | } |
| 112 | return tot, err |
| 113 | } |
| 114 | |
| 115 | func (cr *cipherBlockReaderscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#) WriteToscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#WriteTo().(w ioscip-go gomod github.com/golang/go/src go1.21 io/.Writerscip-go gomod github.com/golang/go/src go1.21 io/Writer#) (int64, error) { |
| 116 | return cr.writeToNscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#writeToN().(w, -1) |
| 117 | } |
| 118 | |
| 119 | func newCipherBlockReaderscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/newCipherBlockReader().(r byteReaderscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/byteReader#, mode cipherscip-go gomod github.com/golang/go/src go1.21 `crypto/cipher`/.BlockModescip-go gomod github.com/golang/go/src go1.21 `crypto/cipher`/BlockMode#) *cipherBlockReaderscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader# { |
| 120 | return &cipherBlockReaderscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#{ |
| 121 | brscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#br.: r, |
| 122 | modescip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#mode.: mode, |
| 123 | blockscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#block.: make([]byte, mode.BlockSizescip-go gomod github.com/golang/go/src go1.21 `crypto/cipher`/BlockMode#BlockSize().()), |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | // newAesDecryptReader returns a cipherBlockReader that decrypts input from a given io.Reader using AES. |
| 128 | func newAesDecryptReaderscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/newAesDecryptReader().(r byteReaderscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/byteReader#, key, iv []byte) (*cipherBlockReaderscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#, error) { |
| 129 | block, err := aesscip-go gomod github.com/golang/go/src go1.21 `crypto/aes`/.NewCipherscip-go gomod github.com/golang/go/src go1.21 `crypto/aes`/NewCipher().(key) |
| 130 | if err != nil { |
| 131 | return nil, err |
| 132 | } |
| 133 | mode := cipherscip-go gomod github.com/golang/go/src go1.21 `crypto/cipher`/.NewCBCDecrypterscip-go gomod github.com/golang/go/src go1.21 `crypto/cipher`/NewCBCDecrypter().(block, iv) |
| 134 | return newCipherBlockReaderscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/newCipherBlockReader().(r, mode), nil |
| 135 | } |
| 136 | |
| 137 | type cipherBlockFileReaderscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockFileReader# struct { |
| 138 | archiveFilescip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockFileReader#archiveFile. |
| 139 | cbrscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockFileReader#cbr. *cipherBlockReaderscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader# |
| 140 | } |
| 141 | |
| 142 | func (cr *cipherBlockFileReaderscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockFileReader#) ReadBytescip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockFileReader#ReadByte().() (byte, error) { |
| 143 | return cr.cbrscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockFileReader#cbr..ReadBytescip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#ReadByte().() |
| 144 | } |
| 145 | |
| 146 | func (cr *cipherBlockFileReaderscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockFileReader#) Readscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockFileReader#Read().(p []byte) (int, error) { |
| 147 | return cr.cbrscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockFileReader#cbr..Readscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#Read().(p) |
| 148 | } |
| 149 | |
| 150 | func (cr *cipherBlockFileReaderscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockFileReader#) WriteToscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockFileReader#WriteTo().(w ioscip-go gomod github.com/golang/go/src go1.21 io/.Writerscip-go gomod github.com/golang/go/src go1.21 io/Writer#) (int64, error) { |
| 151 | return cr.cbrscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockFileReader#cbr..WriteToscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#WriteTo().(w) |
| 152 | } |
| 153 | |
| 154 | func (cr *cipherBlockFileReaderscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockFileReader#) writeToNscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockFileReader#writeToN().(w ioscip-go gomod github.com/golang/go/src go1.21 io/.Writerscip-go gomod github.com/golang/go/src go1.21 io/Writer#, n int64) (int64, error) { |
| 155 | return cr.cbrscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockFileReader#cbr..writeToNscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockReader#writeToN().(w, n) |
| 156 | } |
| 157 | |
| 158 | func newAesDecryptFileReaderscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/newAesDecryptFileReader().(r archiveFilescip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/archiveFile#, key, iv []byte) (*cipherBlockFileReaderscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockFileReader#, error) { |
| 159 | cbr, err := newAesDecryptReaderscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/newAesDecryptReader().(r, key, iv) |
| 160 | if err != nil { |
| 161 | return nil, err |
| 162 | } |
| 163 | return &cipherBlockFileReaderscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockFileReader#{archiveFilescip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockFileReader#archiveFile.: r, cbrscip-go gomod github.com/nwaples/rardecode/v2 . `github.com/nwaples/rardecode/v2`/cipherBlockFileReader#cbr.: cbr}, nil |
| 164 | } |